【发布时间】:2017-01-18 09:15:24
【问题描述】:
这是我的对象:
$scope.steps = {
service: {
selected_service: '',
selected_month: '',
selected_year: '',
selected_day: ''
},
payment: {
selected_dd_type: '',
cc: {
selected_card_type: '',
credit_card_number: '',
name_on_card: '',
expiry_month: '',
expiry_year: ''
},
bank_acc: {
bsb_number: '',
account_number: '',
account_holder_name: ''
}
},
agreement: {
agreement_acceptance: false
}
}
这里是$watchCollection:
$scope.$watchCollection('steps.service', function(newVal, oldVal) {
$scope.canExit = true;
});
$scope.$watchCollection('steps.payment', function(newVal, oldVal) {
$scope.canExit = true;
}, true);
$scope.$watchCollection('steps.payment.cc', function(newVal, oldVal) {
$scope.canExit = true;
}, true);
$scope.$watchCollection('steps.payment.bank_acc', function(newVal, oldVal) {
$scope.canExit = true;
}, true);
$scope.$watchCollection('steps.agreement', function(newVal, oldVal) {
$scope.canExit = true;
}, true);
一切正常。
$watch$scope.steps 对象必须有更好的方法。
如果我 $watch steps 它不会工作。我猜 Angular 看不够深入
$scope.$watchCollection('steps', function(newVal, oldVal) {
$scope.canExit = true;
}, true);
感谢您的指导。
【问题讨论】:
标签: javascript angularjs angularjs-scope watch