我尝试将 http 提供程序导入服务,但出现以下错误:
无法解析“AppService”(?) 的所有参数。确保所有参数都用 Inject 修饰或具有有效的类型注释,并且“AppService”用 Injectable 修饰。
以下是一些代码片段:
<script src="~/es6-shim/es6-shim.min.js"></script>
<script src="~/systemjs/dist/system-polyfills.js"></script>
<script src="~/angular2/bundles/angular2-polyfills.js"></script>
<script src="~/systemjs/dist/system.src.js"></script>
<script src="~/rxjs/bundles/Rx.js"></script>
<script src="~/angular2/bundles/angular2.dev.js"></script>
<script src="~/angular2/bundles/http.dev.js"></script>
<!-- 2. Configure SystemJS -->
<script>
System.config({
map: { 'rxjs': 'RCO/rxjs' },
packages: {
RCO: {
format: 'register',
defaultExtension: 'js'
},
'rxjs': {defaultExtension: 'js'}
}
});
System.import('RCO/Areas/ViewOrganization/AngularTemplates/boot')
.then(null, console.error.bind(console));
引导.ts
import {bootstrap} from 'angular2/platform/browser'
import {HTTP_PROVIDERS} from 'angular2/http'
import 'rxjs/add/operator/map'
import {AppComponent} from 'RCO/Areas/ViewOrganization/AngularTemplates/app.component'
import {AppService} from 'RCO/Areas/ViewOrganization/AngularTemplates/app.service'
bootstrap(AppComponent, [HTTP_PROVIDERS, AppService]);
应用服务.ts
import {Injectable} from 'angular2/core';
import {Http, Response} from 'angular2/http';
import {Observable} from 'rxjs/Rx';
@Injectable()
export class AppService {
constructor(private http: Http) { }
// Uses http.get() to load a single JSON file
getTableData() {
return this.http.get('...').map((res: Response) => res.json());
}
}
我正在尝试调用服务器上的控制器以最终将 JSON 文件加载到数据表中。非常简单的东西,但我加载 Http 模块的方式似乎是错误的。任何帮助都感激不尽。