我想以惰性模式加载一些数据。 特别是,假设我有一个像这样的对象:
$scope.person = {
name: 'Stefano',
surname: 'Rossi',
address: 'Orange Road',
city: {
clazz: 'foo.bar.City',
id: 5,
lazy: true
}
}
使用 Angular,我可以毫无问题地将前三个属性绑定(bind)到 html 标签。
<input ng-model="person.name">
<input ng-model="person.surname">
<input ng-model="person.address">
而且效果很好。
但是假设我想添加城市解码,如果对象是惰性的,我可以与 ngBinding 或 ngModel 进行交互以进行测试,因此通过 promise 获得真正的值(我认为通过 $http 服务获得)
我尝试扩展 ngmodel 但没有正确的 $scope...
https://jsfiddle.net/qq4gqn6t/13/
有人知道如何在 ngbinding 上与 ngmodel 交互吗?
提前致谢
最佳答案
由于双向数据绑定(bind)模型一旦安装在 View 上就可能会延迟加载。 这是一个在事件上加载模型的粗略示例,使您能够进行任何其他更改。
$scope.loadlater = function() {
$scope.person = {
name: 'Stefano',
surname: 'Rossi',
address: 'Orange Road',
city: {
clazz: 'foo.bar.City',
id: 5,
lazy: true
}
}
}
关于javascript - Angularjs:如何在惰性模式下加载模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35046321/