Here is my object:
$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
}
}
Here are the $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);
Everything is working fine.
There must be a better way to $watch
the $scope.steps
object.
If I $watch
steps
it is not going to work. I guess Angular can't watch deep enough
$scope.$watchCollection('steps', function(newVal, oldVal) {
$scope.canExit = true;
}, true);
Thank you for your guidance.