![](/img/trans.png)
[英]Angular 2 Error: (SystemJS) Can't resolve all parameters for Member: (?).(…)
[英]Angular 2 Error: (SystemJS) Can't resolve all parameters for Component Service: (?)
我试图从Visual Studio的Angular2 Component服务中调用Web API,但是不断出现“((SystemJS)无法解析周年服务的所有参数:(?)”之类的错误。
如果删除组件服务,我的示例应用程序将正常运行。
ComponentService:
import { Injectable } from '@angular/core';
import {Http, Response } from '@angular/http';
import { IData } from '../Common/details';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
export class AniversaryService {
constructor(private _http:Http) { }
getImages(): Observable<IData[]> {
return this._http.get("/api/ImageService/Details")
.map((response: Response) => <IData[]>response.json()
};
}
和我的相应组件:
import { Component, OnInit } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
import { IData } from '../Common/details';
import { AniversaryService } from './Aniversary.service';
@Component({
selector: 'my-AniversaryComponent',
providers: [AniversaryService]
})
export class AniversaryComponent implements OnInit {
data: IData[];
constructor(private _aniversaryservice: AniversaryService) { }
ngOnInit() {
this._aniversaryservice.getImages().subscribe((details) => this.data
=details);
}
}
}
我尝试了与堆栈溢出不同的解决方案,但对我没有任何帮助。
请帮助我克服这个问题。
先谢谢您的帮助
该服务似乎缺少@Injectable装饰器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.