简体   繁体   中英

Typescript: Data bind between service and controller such that utilization of variable is simple

Since value assignment doesn't bind data, this -> this.arrayVal = someService.arrayVal doesn't work. Is there a way to overcome this?

The goal here is to keep the assignment simple in HTML and controller ie. using Ctrl.arrayVal instead of Ctrl.someService.arrayval

Controller:

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
    }

}
}

Service:

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

Ctrl.arrayVal instead of Ctrl.someService.arrayval

You can just put someService directly on the scope. Then use someService.arrayVal in html and controller.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM