Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dependency injection angular2依赖项注入错误_Dependency Injection_Angular - Fatal编程技术网

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");
    }
}