当页面使用以下代码加载时,手表才首次工作:
import angular from 'angular';
import '../style/app.css';
class AppCtrl {
constructor($scope) {
this.url = 'https://github.com/preboot/angular-webpack';
this.val = 0;
this.even = true;
this.scope = $scope;
this.scope.$watch('val', this.valChanged());
}
inc() {
this.val++;
this.even = this.val % 2 == 0 ? true : false;
}
valChanged(newVal, oldVal) {
console.log('changed');
}
}
AppCtrl.$inject = ['$scope'];
const MODULE_NAME = 'app';
angular.module(MODULE_NAME, [])
.controller('AppCtrl', AppCtrl);
export default MODULE_NAME;每当我单击调用inc()方法的按钮时,都会更新值,但不会触发valChanged方法。
使用angularjs诉1.5
发布于 2017-03-16 07:49:59
this.scope.$watch(() => this.val,
(newVal, oldVal) => this.valChanged(newVal, oldVal));https://stackoverflow.com/questions/42828069
复制相似问题