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