我有以下情况。我有两个共享相同模型的 Angular 组件。
第一个组件在某个时候更新了shared
模型,我希望能够在第二个组件中选择该更新。我尝试做这样的事情:
@NgComponent(...)
class MySecondComponent {
Scope scope;
NgModel ngModel;
String someValue;
MySecondComponent(this.ngModel, this.scope) {
imagsomeValueeUrl = ngModel.modelValue;
scope.$watch('ngModel.modelValue', (newValue, oldValue, _this) {
someValue = newValue;
});
}
}
有什么建议吗?
使用 NgModel.render 隐式侦听更改:
MySecondComponent(this.ngModel) {
ngModel.render = (String modelValue) {
someValue = modelValue;
}
}