Angular 2 – NgFor using numbers instead collections

Within your component, you can define an array of number (ES6) as described below: export class SampleComponent { constructor() { this.numbers = Array(5).fill().map((x,i)=>i); // [0,1,2,3,4] this.numbers = Array(5).fill(4); // [4,4,4,4,4] } } See this link for the array creation: Tersest way to create an array of integers from 1..20 in JavaScript. You can then iterate … Read more

Property ‘value’ does not exist on type EventTarget in TypeScript [duplicate]

event.target here is an HTMLElement which is the parent of all HTML elements, but isn’t guaranteed to have the property value. TypeScript detects this and throws the error. Cast event.target to the appropriate HTML element to ensure it is HTMLInputElement which does have a value property: (event.target as HTMLInputElement).value Per the documentation: Type the $event … Read more

ngOnInit not being called when Injectable class is Instantiated

Lifecycle hooks, like OnInit() work with Directives and Components. They do not work with other types, like a service in your case. From docs: A Component has a lifecycle managed by Angular itself. Angular creates it, renders it, creates and renders its children, checks it when its data-bound properties change and destroy it before removing … Read more

Property ‘map’ does not exist on type ‘Observable’

You need to import the map operator: import ‘rxjs/add/operator/map’ Or more generally: import ‘rxjs/Rx’; Notice: For versions of RxJS 6.x.x and above, you will have to use pipeable operators as shown in the code snippet below: import { map } from ‘rxjs/operators’; import { HttpClient } from ‘@angular/common/http’; // … export class MyComponent { constructor(private … Read more

TSLint extension throwing errors in my Angular application running in Visual Studio Code

Like Tuấn Nguyễn described, you need to: Go to the Command Palette by pressing Ctrl + Shift + P, In the input that pops up at the top of the Visual Studio Code, start typing TSLint: Manage workspace library execution” and hit the Enter key. From the menu that replaces the input, pick enable workspace … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)