1
我已经配置了一个途径,并尝试将参数传递给控制器:
app.js
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('spot', {
url: "/spot/:param",
templateUrl: "templates/spot.html",
controller: "SpotCtrl"
});
$urlRouterProvider.otherwise('/');
});
控制器:
angular.module('spotx.controllers')
.controller('SpotCtrl', ['$scope', '$routeParams',
function($scope, $routeParams) {
$scope.do = function() {
console.log($routeParams.param);
};
}])
的网址是/#/ spot/1111,但是如果我开启do-function,我会得到undefined在控制台中。
我已经包含了angular-route.min.js并将ngRoute注入到我的应用程序中。 – rakete
所以你有2个路由器在页面中?如果使用UI路由器,则不需要'ngRoute' – charlietfl
您知道我使用的是UI路由器吗? – rakete