2016-01-14 28 views
0

任何時候我有一個$注入我的服務是失敗的。我似乎無法找到錯誤。如果我註釋掉構造函數中的注入和參數,它可以正常工作。

感謝

module app.common { 
export interface IHelloService { 
    sayHello(text: string): string; 
    sayGoodbye(text: string): string 
} 
export class HelloService implements IHelloService { 
    // lokiInst: Loki; 
    // idbAdapter: LokiIndexedAdapter; 
    // usersCollection: LokiCollection<starter.domain.User>; 

    static $inject = ["$scope"]; 
    constructor(private $scope:ng.IScope) { 

    } 


    sayHello(text: string): string { 
     return "hello" + text; 
    }; 
    sayGoodbye(text: string): string { 
     return "goodbye"+ text; 
    }; 
} 


angular.module("app.common", []); 

angular 
    .module("starter") 
    .service("helloService", 
    HelloService); 
} 

回答

0

不能從服務中導入$scopeSee the docs on this point - 只有控制器可以訪問這個。

取決於你打算做什麼(此代碼不使用$scope所以很難猜測),你可以導入$rootScope代替,或者Hello應該是一個控制器,而不是服務。