Article From:https://segmentfault.com/q/1010000009556472
Question:
  1. Routing settings (there is a father child relationship between the two State):

.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.The code in the controller of parent State:

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

3.The code in the controller of sub State:

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

You can jump to a child state, but you can’t receive parameters in the controller of the child state (the result of accessing parameters is undefined, not “123456”). Read the online information should be written correctly, is it related to the father child relationship between State?

Answer 0:

There is a problem with your router definition. Params need to be at the same level as URL and views. Views, as it literally means, specify the ui. If you specify params there is a problem. It needs to be changed as follows:

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

Answer 1:

$broadcast,I remember that event broadcasting should be used to propagate events from parent scope to child scope. You can do something about it, and it should be able to solve it.

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *