您好,我正在研究 AngularJS 组件,需要帮助如何在 Constructor() 中使用 $watch,如下所示,我附上了我的代码结构。
import template from './Mypage.component.html';
export const MyComponent = {
template,
bindings: {
myData: '<'
},
controller: class MyController {
constructor($scope) {
$scope.$watch(() => this.myData, newVal => {
this._myFunction();
});
}
}
最佳答案
使用 $onChanges()
方法代替 $scope.$watch()
class MyController {
constructor() {
// Your constructor...
}
$onChanges(changedObj){
// Expect myData changes
console.log(changedObj)
}
}
更多信息 here
关于javascript - Angularjs 组件和 $watch 在 ES6 中绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44311778/