我已經使用$ routeProvide將頁面從一個頁面重定向到另一個頁面,並且我在url中傳遞了一些動態參數。
它在一個地方工作,不與另一個地方工作。
我的代碼:在app.js
app.config(['$routeProvider', '$locationProvider',
function ($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl: "client/home/home.html",
controller: "IndexCtrl",
access: {
isloggedIn: false
}
})
.when('/test/:searchTerm', {
templateUrl: "client/test.html",
controller: "testController",
access: {
isloggedIn: false
}
})
.when('/test2/:id', {
templateUrl: "client/index.html",
controller: "indexController",
access: {
isloggedIn: true
}
})
.otherwise({
redirectTo: "/"
});
}]);
在控制器文件
:對於時候的TestController我打網址 server.com/#/test/45在控制檯45和indexController的了,當我打URL服務器.com /#/ test2/45然後我得到:控制檯中的id。
app.controller("testController", ['$location', '$rootScope', '$routeParams', function ($location, $rootScope, $routeParams) {
console.log($routeParams.searchTerm); //get result 45
}]);
app.controller("indexController", ['$location', '$rootScope', '$routeParams', function ($location, $rootScope, $routeParams) {
console.log($routeParams.id); //get result :id
}]);
爲什麼發生這種情況有人可以幫忙嗎?應該是什麼問題?
是URL路徑:表示 '/ TEST2/ID'是正確的? –
分享你的html也 –
@ebinmanuva我已經把只有測試文本都在HTML和兩者都存在的位置 – Nitin