2016-09-16 7 views
0

Ich habe eine Angular 1.5-Komponente in TypeScript geschrieben und ich würde gerne wissen, wie auf die Bindungen im Controller zugreifen.Angular 1.5-Komponente in TypeScript mit Bindungen

Hier ist sie:

export interface IMyController { 
    myMethod:() => void; 
} 

class MyController implements IMyController { 
    $onInit(): void { 
    } 
    public myMethod(): void { 
    } 
} 

angular.module('mymodule').component(
    'myCmp', { 
     controller: MyController, 
     controllerAs: 'vm', 
     templateUrl: 'myCmp.component.html', 
     bindings: { 
      data: '=', 
      label: '=' 
     } 
}); 

Kann mir jemand helfen?

Antwort

0

Sie wurden nur Ihrem Klassenobjekt zugewiesen. Versuchen Sie daher, einige Daten für Bindungen einzubinden, und versuchen Sie dann, darauf zuzugreifen.

class MyController implements IMyController { 
$onInit(): void { 
    console.log(this.data, this.label); 
} 
public myMethod(): void { 
} 
} 

angular.module('mymodule').component(
    'myCmp', { 
    controller: MyController, 
    controllerAs: 'vm', 
    templateUrl: 'myCmp.component.html', 
    bindings: { 
     data: '=', 
     label: '=' 
    } 
}); 
0

Ich habe gerade getan:

class MyController implements IMyController { 
    public data: string; 
    public label: string; 
    $onInit(): void { 
    } 
    public myMethod(): void { 
    } 
} 

und es funktionierte.

Verwandte Themen