登录测试后,我尝试进入主页,但遇到问题。我使用 $location.path("/templates/welcome.html"); 但它不起作用。
我在 app.js 中的 Controller 是:
controller('SignInCtrl', function($scope, $state, $http) {
$scope.login = function(user) {
$http.get("http://localhost/app_dev.php/json/login/"+user.username+"/"+user.password)
.then(function(response){
console.log(response.data.status);
if(response.data.status === 200)
{
alert("redirect to main page");
$location.path("/templates/welcome.html");
}else if(response.data.status === 403){
alert("Login or password incorrect");
}else{
alert("User not found");
}
});
};
})
警报有效,但重定向不起作用。在控制台中我有这个错误:
ionic.bundle.js:25642 ReferenceError: $location is not defined
at app.js:37
最佳答案
像这样将$location注入(inject)到 Controller 中
controller('SignInCtrl', function($scope, $state, $http, $location) {
关于javascript - ionic 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36789131/