【发布时间】:2015-11-22 01:52:21
【问题描述】:
当登录成功时,我尝试重定向其他页面,在这种情况下,我使用了演示页面 index.html 成功。但是 $location.path 没有重定向到新页面。我收到错误类型错误:无法读取未定义的属性“路径”。
module LoginModule {
export class LoginController {
username: string;
password: string;
static $inject = ['$http','$location'];
constructor(private $http : ng.IHttpService,private $location : ng.ILocationService){
}
login() {
this.$http({
method: 'POST',
url: 'https://localhost:8061/nada/login',
data : $.param({'username' : this.username, 'password' : this.password}),
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}}).success(function(data) {
this.$location.path("/success");
//alert("sucess");
}).error(function(error) {
JSON.parse(error);
alert('No access available.');
// console.log(result);
});
}
}
angular.module('loginModule', ['ngRoute']).controller('LoginController', LoginModule.LoginController).config(['$routeProvider' ,function($routeProvider) {
$routeProvider.
when("/", {
templateUrl: 'html/login.html'
})
.when("/success", {
templateUrl: 'html/index.html',
controller: 'clientsController'
})
.otherwise({redirectTo: '/'});
}]);
}
我的代码中是否缺少某些内容。此外,我已将路由部分放在 .config 方法中,我可以将它移动到一个类中,因为我试图在 typescript 中这样做,如果是这样,我如何在 mycontroller 中访问它。
我有接受用户名和密码的登录页面。并打个休息电话
【问题讨论】:
标签: angularjs typescript