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');
}
$http.getreturns a promise object, and the problem occurs here because when you completely replace one reference with another, angular doesn't update the bindings. managing a local array and pushing/splicing data into and out of it is less of a hack than the alternative, which would involve using the$compileservice.this.arrayVal = someService.arrayVal;withangular.extend(this.arrayVal, someService.arrayVal);