是的,關於此主題的問題很多。但我無法解決我的問題。從AngularJS的當前網址讀取參數
這裏是我的網址
http://localhost/resetpassword.html/7f18114f-1e1b-4c73-bf0f-f9e6f5bbb293
而且用戶可以通過點擊電子郵件中提供的鏈接來獲得此屏幕。我嘗試使用$ routeParams,$ location.search()但找不到我的參數。
我使用nodejs作爲我的web服務器。從服務器端路由,我添加了以下路由來處理請求。
app.get('/resetpassword.html/:resetcode', function (req, res) {
console.log("reset code: " + req.params.resetcode);
//res.render('resetpassword.html/' + req.params.resetcode);
res.render('resetpassword.html', { resetcode: req.params.resetcode });
});
而我的角度配置如下
app.config(function ($routeProvider, $locationProvider) {
$routeProvider
.when('/', { templateUrl: 'home.html' })
.when('/resetpassword.html/:resetcode', { templateUrl: '/resetpassword.html', controller: 'ResetPasswordCtrl' })
.otherwise({ redirectTo: '/' })
;
$locationProvider.html5Mode(true);
})
我可以訪問從$位置的路徑,所以我可以解析的查詢字符串。但這是我擁有的唯一方式嗎?
感謝
感謝您的回覆。但我得到一個空的物體。 – Naresh