Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Angular 2 constructor not accepting parameters in ASP.NET 5

$
0
0

If I pass parameters to the constructor the app stops working. This seems to be related solely to ASP.NET 5.

app.component.ts

import { Component } from 'angular2/core';
import { DataService } from './data.service';

@Component({ 
    selector: 'app',
    providers: [DataService],
  template: `<h1>Hello World</h1><li *ngFor="#customer of customers"><span>{{customer.firstName}}</span> </li>
`
})
export class AppComponent {
    public customers: any[];

    constructor(private dataService: DataService) {
        this.dataService = dataService;
    }


    ngOnInit() {
        this.dataService.getCustomers()
            .subscribe((customers: any[]) => {
                this.customers = customers;
            }); 
    }
}

data.service.ts

import { Injectable } from 'angular2/core';
import { Http, Response } from 'angular2/http';
import 'rxjs/add/operator/map';

@Injectable()
export class DataService {

    constructor(private http: Http) {
        this.http = http;
    }

    getCustomers() {
        return this.http.get('customers.json')
            .map((res: Response) => res.json());
    }

}


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>