我正在尝试从重置密码电子邮件中的链接检索重置密码 token 。该链接使用我尝试获取的 token 将用户发送回我的 Node/Angular 应用程序。
Laravel API:电子邮件模板
<td class="content">
<a href="http://localhost:3000/reset-password?token={{$token}}">Reset Your Password</a>
</td>
Node/Angular 应用程序: ResetPassword.ejs 模板:我正在使用 Angular Controller :
<div ng-controller="resetPasswordCtrl">
...stuff
</div>
重置密码 Controller :
'use strict';
angular
.module('myApp')
.controller('resetPasswordCtrl', ['$scope', '$routeParams', '$location', function($scope, $routeParams, $location) {
console.log('ROUTE PARAMS', $routeParams); //object with a bunch of getters/setters
console.log('ROUTE PARAMS', $routeParams.token); //undefined
console.log('Location', $location.search('token')); //LocationHashbangUrl
console.log('Location', $location.search().token); //true
console.log('Location', $location.search()['token']); //true
console.log('Route current params', $route); //empty route object
}]);
对于 LocationHashbangUrl ($location.search('token')
),我知道我正在使用 token 获取正确的 url,因为 $$absUrl 显示了它。
为什么我无法使用 Controller 中显示的其中一种方法检索 token
参数?
最佳答案
您可以发布您的 $routeProvider 吗?您可以在那里添加 token 作为参数,然后 $routeParams.token 将执行您想要的操作。像这样:
$routeProvider.when('/reset-password/:token')
这意味着您的重设密码 url 看起来像这样:
http://localhost:3000/reset-password/{{$token}}
关于javascript - 从 url 获取路由参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31944169/