javascript - The $rootScope global variable has been updated in the controller of the data entry page, but the variable is still the old value when accessed during beforeLeave?
阿神
阿神 2017-05-31 10:41:00
0
1
617

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? ? ?

阿神
阿神

闭关修行中......

reply all(1)
巴扎黑

It’s best not to use ionic, caching is a big pitfall. . .

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template