我试图创建一个样本angular2服务并使用它,但我不确定我所做的错误。服务方法不能由组件调用,请参阅plunker更多细节https://plnkr.co/edit/tlnGU9Er6GxsOaUMCZZG?p=previewangular2服务方法没有被调用
我的服务代码看起来像下面
import { Injectable } from 'angular2/core';
import { HTTP_PROVIDERS, Http, Headers, Response, JSONP_PROVIDERS, Jsonp } from 'angular2/http';
import { Configuration } from './Configuration';
import 'rxjs/add/operator/map'
import { Observable } from 'rxjs/Observable';
///Service class to call REST API
@Injectable()
export class SampleService {
items: Array<any>;
constructor() {
this.items = [
{ name: 'Test1' },
{ name: 'Test2' },
{ name: 'Test3' }
];
}
getItems() {
return this.items;
}
}
使用新的 - >角度 - > 2.0 TS http://take.ms/AJTLh – yurzui
你是index.html页面不包括任何anuglar2代码,它不会被设置为从typescript转换到javascript使用System.js。请考虑以下教程以完成缺少的peices:https://angular.io/docs/ts/latest/quickstart.html – Tucker
请注意,您的组件文件名是'SampleCompoent.ts' –