Angularjs $stateChangeSuccess然后r$outeParams仍然为空object@Sami:您需要使用$stateParams而不是$routeParams。对于我,$routeChangeSuccess有时没有触发,$route.current.p
Angularjs $stateChangeSuccess然后r$outeParams仍然为空object@Sami:您需要使用$stateParams而不是$routeParams。对于我,$routeChangeSuccess有时没有触发,$route.current.p,angularjs,Angularjs,$stateChangeSuccess然后r$outeParams仍然为空object@Sami:您需要使用$stateParams而不是$routeParams。对于我,$routeChangeSuccess有时没有触发,$route.current.params保存了我!谢谢你,伙计! <body ng-controller="MainController"> <div id="terminal"></div> <div ng-view&g
$stateChangeSuccess
然后r$outeParams
仍然为空object@Sami:您需要使用$stateParams而不是$routeParams。对于我,$routeChangeSuccess
有时没有触发,$route.current.params
保存了我!谢谢你,伙计!
<body ng-controller="MainController">
<div id="terminal"></div>
<div ng-view></div>
<!-- including scripts -->
</body>
$routeProvider.when("/view1", {
templateUrl: "partials/partial1.html"
controller: "MyCtrl1"
})
$routeProvider.when("/view2", {
templateUrl: "partials/partial2.html"
controller: "MyCtrl2"
})
// I'm not defining MainController here!!
$routeProvider.when("/view2/name1/:a/name2/:b"
var myapp = angular.module(...);
myapp.controller('MainCtrl', function ($scope) {...}
angular.module('MyModule')
.controller('MainController', ["$scope", function ($scope) {
$scope.parentMethod = function($routeParams) {
//do stuff
}
}]);
angular.module('MyModule')
.controller('MyCtrl1', ["$scope", function ($scope) {
$scope.parentMethod($routeParams);
}]);
angular.module('MyModule')
.controller('MyCtrl2', ["$scope", function ($scope) {
$scope.parentMethod($routeParams);
}]);
angular.module('MyModule')
.controller('MainCtrl', function ($scope, $routeParams, $timeout) {
$timeout(function(){
// do stuff with $routeParams
console.log('routeParams:'+JSON.stringify($routeParams));
}, 20);
});
angular.module('MyModule')
.controller('MainCtrl', function ($scope, $route) {
console.log('routeParams:'+JSON.stringify($route.current.params));
});
.controller('MainCtrl', function ($scope, $routeParams, MainFactory, $rootScope) {
$scope.contents = MainFactory.getThing($routeParams.id);
$rootScope.total = MainFactory.getMax(); // Send total to the rootScope
}
.controller('IndexCtrl', function($scope, $rootScope){
// Some code
});