组件中的属性与服务
Attributes vs Services in Components
在angular的组件之间传递数据是属性多还是使用服务好?
这个比较好:
app.component("name",{
bindings:{
data:'<'
}
})
或者这样:
app.component("name",{
bindings:{}
controller: function(myService){
this.data= myService.data;
}
})
我喜欢构建我的应用程序,以便服务成为数据源,并且绑定应该将数据从接收组件向下传递给它的子组件。任何兄弟组件也可以直接从服务接收数据,但子组件应该通过绑定向下传递数据,而不是直接从服务接收数据。
在angular的组件之间传递数据是属性多还是使用服务好? 这个比较好:
app.component("name",{
bindings:{
data:'<'
}
})
或者这样:
app.component("name",{
bindings:{}
controller: function(myService){
this.data= myService.data;
}
})
我喜欢构建我的应用程序,以便服务成为数据源,并且绑定应该将数据从接收组件向下传递给它的子组件。任何兄弟组件也可以直接从服务接收数据,但子组件应该通过绑定向下传递数据,而不是直接从服务接收数据。