시계는 다음 코드를 사용하여 페이지를로드 할 때 처음으로 만 작동합니다.
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 v 1.5 사용
this.scope.$watch(() => this.val,
(newVal, oldVal) => this.valChanged(newVal, oldVal));
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다