如何在URL-angularjs中传递和读取多个参数
有两个视图具有各自的控制器。 链接位于View1中。单击此链接应加载View2并读取参数。 这是我尝试过的,但警告说-未定义。 View2可以加载带/不带参数-每个案例具有不同的工作流 View1.html:如何在URL-angularjs中传递和读取多个参数,angularjs,Angularjs,有两个视图具有各自的控制器。 链接位于View1中。单击此链接应加载View2并读取参数。 这是我尝试过的,但警告说-未定义。 View2可以加载带/不带参数-每个案例具有不同的工作流 View1.html: <div ng-controller="view1ctrl"> <a href="#/view2/pqid/775/cid/4" >Link1</a> </div> var app = angular.module('app', ['ngR
<div ng-controller="view1ctrl">
<a href="#/view2/pqid/775/cid/4" >Link1</a>
</div>
var app = angular.module('app', ['ngRoute']);
app.config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when('/view1', {
templateUrl: 'App/views/view1.html',
controller: 'view1ctrl'
})
.when('/view2', {
templateUrl: 'App/views/view2.html',
controller: 'view2ctrl'
})
.when('/view2/:pqid/:cid', {
templateUrl: 'App/views/view2.html',
controller: 'view2ctrl'
})
.otherwise({
redirectTo: '/view1'
});
}]);
app.controller("view2ctrl", ['$scope','$routeParams',function ($scope, $routeParams) {
var init = function () {
alert($routeParams.pqid);
}
init();
}]);
view2ctrl.js:
<div ng-controller="view1ctrl">
<a href="#/view2/pqid/775/cid/4" >Link1</a>
</div>
var app = angular.module('app', ['ngRoute']);
app.config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when('/view1', {
templateUrl: 'App/views/view1.html',
controller: 'view1ctrl'
})
.when('/view2', {
templateUrl: 'App/views/view2.html',
controller: 'view2ctrl'
})
.when('/view2/:pqid/:cid', {
templateUrl: 'App/views/view2.html',
controller: 'view2ctrl'
})
.otherwise({
redirectTo: '/view1'
});
}]);
app.controller("view2ctrl", ['$scope','$routeParams',function ($scope, $routeParams) {
var init = function () {
alert($routeParams.pqid);
}
init();
}]);
你就快到了:
.when('/view2/:pqid/:cid'
映射到以下格式的URL:
view2/1234/4567
1234为pqid,4567为cid
因此,我认为您的路由正在运行,只需将链接更改为#/view2/775/4即可
或者,如果要保留相同的链接,请将路由更改为:
#/view2/pqid/:pqid/cid/:cid