2015-12-07 57 views
0

我有一個打字稿類 - 業務對象模型:進樣的服務模型

module app.domain { 

    export interface IDefect { 
     defectId: number; 
     comment: string; 
    } 

    export class Defect implements IDefect { 
     defectId: number; 
     comment: string; 
    } 
} 

是否有可能注入AngularJS服務,這種模式在模型的方法來使用它呢?

回答

0

只需使用$ inject語法。例如:

class Service 
{ 
    static $inject = ['$http'];  
    constructor(private $http: ng.IHttpService) 
    { 
    } 

    public MyMethod() 
    { 
     this.$http.get("/") 
      .success(null) 
      .error(null); 
    } 
} 
0

看起來您正在嘗試創建域對象,而不是服務。 Angular中的服務是單例(每個應用程序一個)。爲了能夠對注入的對象執行new,您必須將其定義爲Factory