Why can't I pass parameters between parent and child State via $stateParams? Is it related to the father-son relationship between State?
淡淡烟草味
淡淡烟草味 2017-05-27 17:44:33
0
2
931
  1. Routing settings (there is a parent-child relationship between the two States):

.state("tab.my-profile", {
  url: "/my/profile",
  views: {
    "tab-my": {
      templateUrl: "templates/tab-my-profile.html",
      controller: "MyProfileCtrl"
    }
  }
})
  .state("tab.my-profile-mobileinput", {
    url: "/my/profile/mobileinput",
    views: {
      "tab-my": {
        params: {"mobile": null}
        templateUrl: "templates/util-mobile-input.html",
        controller: "MobileInputCtrl",
      }
    }
  })

2. Code in the controller of the parent State:

.controller("MyProfileCtrl", function ($scope, $state) {
  $scope.goToMobileInput = function () {
    $state.go("tab.my-profile-mobileinput", {"mobile": "123456"})
  };
})

3. Code in the controller of the sub-State:

.controller("MobileInputCtrl", function ($scope, $stateParams) {
  alert($stateParams.mobile);  // undefined
})

Can jump to the sub-State, but cannot receive parameters in the controller of the sub-State (the result obtained when accessing the parameters is undefined, not "123456"). After reading the information on the Internet, this writing should be correct. Is it related to the father-son relationship between State?

淡淡烟草味
淡淡烟草味

reply all(2)
黄舟

There is something wrong with your router definition. Params need to be at the same level as url and views. Views, as the name suggests, specify ui. If you specify params in it, there is a problem. You need to change it to the following:

  .state("tab.my-profile-mobileinput", {
    url: "/my/profile/mobileinput",
    params: {"mobile": null},
    views: {
      "tab-my": {
        templateUrl: "templates/util-mobile-input.html",
        controller: "MobileInputCtrl"
      }
    }
  })
左手右手慢动作

$broadcast, I remember this should use event broadcasting, which can propagate events from the parent scope to the child scope. You can search the relevant content on Baidu and it should be able to solve it

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