打字稿:服务和控制器等之间的数据绑定变量的使用很简单 [英] Typescript: Data bind between service and controller such that utilization of variable is simple
问题描述
由于值分配不绑定的数据,这一点 - > this.arrayVal = someService.arrayVal
不起作用。有没有办法解决这个?
这里的目标是保持在分配HTML和控制器即简单。使用 Ctrl.arrayVal
而不是 Ctrl.someService.arrayval
控制器:
模块控制器{
出口类SomeController { arrayVal:数组< SomeModel取代; 静态$注射= ['someService'];
构造函数(
私人someService:SomeService
){
this.arrayVal = someService.arrayVal;
//我想这样做,因为这将保持在分配HTML简单 - > Ctrl.arrayVal VS Ctrl.someService.arrayval
}}
}
服务:
类SomeService {
arrayVal = $ http.get(的http://地址');
}
Ctrl.arrayVal代替Ctrl.someService.arrayval
块引用>您可以只把
someService
直接的范围。然后使用someService.arrayVal
在HTML中的和的控制器。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 ofCtrl.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 usesomeService.arrayVal
in html and controller.这篇关于打字稿:服务和控制器等之间的数据绑定变量的使用很简单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!