由于值分配不绑定数据,因此-> this.arrayVal = someService.arrayVal不起作用。有办法克服吗?

这里的目标是保持HTML和控制器中的分配简单。使用Ctrl.arrayVal代替Ctrl.someService.arrayval

控制器:

module Controllers {
    export class SomeController {

    arrayVal: Array<SomeModel>;

    static $inject = ['someService'];
    constructor(
    private someService: SomeService
    ){
         this.arrayVal = someService.arrayVal;
//I would like to do this as it would keep the assignment simple in HTML -> Ctrl.arrayVal vs Ctrl.someService.arrayval
    }

}
}


服务:

class SomeService {
     arrayVal = $http.get('http://Address');
}

最佳答案

Ctrl.arrayVal代替Ctrl.someService.arrayval


您可以直接将someService放在示波器上。然后在html和controller中使用someService.arrayVal

10-07 22:02