Code in the controller of the data entry page:
.controller("MobileInputCtrl", function ($scope, $rootScope) {
$scope.$watch("myForm.$dirty", function (newVal) {
$rootScope.isDirty = newVal;
});
})
A test<p> is placed on the data entry page to display the value of the $rootScope.isDirty global variable to prove that the variable value has been correctly updated to true.
$ionicView.beforeLeave() event handling method code registered in the top-level module:
angular.module("app", [])
.run(function ($ionicPlatform, $rootScope) {
$ionicPlatform.ready(function () {
$rootScope.$on("$ionicView.beforeEnter", function (event, view) {
$rootScope.isDirty = false;
});
$rootScope.$on("$ionicView.beforeLeave", function (event, view) {
alert($rootScope.isDirty); // 显示仍然为false,百思不得其解!
});
});
});
In the test of the data entry page, it has been clearly seen that isDirty has been correctly updated to true. But when I left the data entry page, I saw that the isDirty value displayed in the pop-up prompt box was still false. I was puzzled! Could it be that this variable can have two values? ? ?