Dependency injection angular2依赖项注入错误
我试图从组件中的服务类访问一个简单的方法Dependency injection angular2依赖项注入错误,dependency-injection,angular,Dependency Injection,Angular,我试图从组件中的服务类访问一个简单的方法 //myfriend.service.ts export class MyFriendService(){ constructor(){} testMe() { window.alert("im friend service"); } } //myfriend.component.ts import {Component} from 'angular2/core'; import {MyFriendService} from 'app/
//myfriend.service.ts
export class MyFriendService(){
constructor(){}
testMe() {
window.alert("im friend service");
}
}
//myfriend.component.ts
import {Component} from 'angular2/core';
import {MyFriendService} from 'app/components/myfriend/myfriend.service';
@Component({
directives: [],
providers: [MyFriendService],
templateUrl: `app/components/myfriend/myfriend-view.html`
})
export class MyFriendCmp {
constructor(myFriendService: MyFriendService) {
myFriendService.testMe();
}
}
这是一个错误
myFriendService.testMe is not a function.
我在这方面花了很多时间来完成这项工作。但我仍在努力。请帮我解决这个问题。谢谢
哦,你能相信吗?花了很长时间才弄明白。但是你把
不需要括号看这行
导出类MyFriendService()我正在尝试将其引入plunkr,并将为您提供链接。你说的外面是什么意思。我还是导入了它。@micronyks nice eyes+1..甚至我用plunkr花了10分钟就离开了..:这花了太长时间@Pankaj。我觉得一切都很好那有什么问题吗。然后我逐行比较,找出了问题所在。然后我更新了答案,但最近才知道大约22分钟前Nishanthd解决了这个问题。哈哈哈…@micronyks太好了。现在干杯。:)
export class MyFriendService{
constructor(){}
testMe() {
window.alert("im friend service");
}
}