tslint Error – Shadowed name: ‘err’

You are using the same variable “err” in both outer and inner callbacks, which is prevented by tslint. If you want to use the same variable then “no-shadowed-variable”: false, otherwise do as below. fs.readdir(fileUrl, (readDirError, files) => { fs.readFile(path.join(fileUrl, files[0]), function (err, data) { if (!err) { res.send(data); } }); });

What is meaning by @ symbol in typescript –Angular 2

The @ symbol you are referring to is called decorator. Decorators provide a way to add both annotations and a meta-programming syntax for class declarations and members. Basically when you are doing @component you are telling compiler that the class is a angular2 component with the metadata passed as an argument. for eg. @Component({ moduleId: … Read more

Angular 2 router resolve with Observable

Don’t call subscribe() in your service and instead let the route subscribe. Change return this.searchService.searchFields().subscribe(fields => { to import ‘rxjs/add/operator/first’ // in imports return this.searchService.searchFields().map(fields => { … }).first(); This way an Observable is returned instead of a Subscription (which is returned by subscribe()). Currently the router waits for the observable to close. You can … Read more

ngFor create 2 rows

That exists with slightly different syntax: <template ngFor let-element [ngForOf]=”data” let-i=”index”> <tr>…</tr> //row 1 <tr>…</tr> //row 2 </template> or <ng-container *ngFor=”let element of data let i=index”> <tr>…</tr> //row 1 <tr>…</tr> //row 2 </ng-container> update for >= 4.0.0 <template> was changed to <ng-template> <ng-template ngFor let-element [ngForOf]=”data” let-i=”index”> <tr>…</tr> //row 1 <tr>…</tr> //row 2 </ng-template>

Observables : Cancel previous http request on new subscription call

I would use a subject to keep everything reactive. In your template html listen to change events and emit a new value to the subject. <searchBar (change)=”search$.next($event.target.value)” /> then in your component: this.subscription = this.search$.pipe( debounceTime(800), distinctUntilChanged(), switchMap(searchText=>http.post(‘api_link’, {searchText}) }).subscribe(response=>{ this.response = response. }); The switchMap will cancel any HTTP request that hasn’t completed if … Read more

TS2307: Cannot find module ‘angular2/core’ while importing Angular2 on TypeScript

As you are new to TypeScript. I still suggest you to follow angular.io docs for 5 min startup. That has specific instruction and quite well explained to get started with it. Angular2 5 min quickstart page @ angular.io. What you need to have basically to start: Node.js with npm package manager. Typescript with compiler. A … Read more

How to use angular 2 service with Ionic 2?

There is no use of Bootstrap() in Ionic2, only use of @App to declare your app. You still need to declare your service in your @Page component. Create your service import {Injectable} from “angular2/core”; import {Http} from “angular2/http”; @Injectable() export class DataService { constructor(http: Http) { this.http = http; this.data = null; } retrieveData() { … Read more