2013-12-09 87 views
2

是的,關於此主題的問題很多。但我無法解決我的問題。從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); 
}) 

我可以訪問從$位置的路徑,所以我可以解析的查詢字符串。但這是我擁有的唯一方式嗎?

感謝

回答

0

您必須配置您的路線這樣才能夠使用$routeParams

$routeProvider.when('/resetpassword.html/:resetcode', /**route**/); 

然後你應該能夠使用$routeParams.resetcode得到重置代碼。

+0

我已經有提到的配置,但仍然無法正常工作。 – Naresh

+0

您是否嘗試過使用多個瀏覽器?它適用於我,但只有在關閉「html5Mode」時才適用。 – Mouagip