Redirection Ionic
Redirection Ionic
本文关键字:Ionic Redirection 更新时间:2023-09-26
我试图使用Ionic从一个活动移动到另一个活动。我没有任何错误,但这个动作不起作用。
我的状态是:
.config(函数($stateProvider){$stateProvider.state("索引"{templateUrl:"index.html",url:"/"}).state('home'{templateUrl:"templates/welcome.html",url:'/home'});})
我的控制器是:
.controller('HomeCtrl', function($scope, $state, $http, $location) {
$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("/home");
}else if(response.data.status === 403){
alert("Login or password incorrect");
}else{
alert("User not found");
}
});
};
})
当我收到Json时,我没有错误,但重定向不会显示
我认为你几乎混淆了状态和位置,我建议保持简单,只使用状态。
尝试注入$state并使用它,正如我所看到的,你有一个定义为"Home"的状态,也许这应该做到:
$state.go("home");
而不是使用
$location.path
我希望这能帮助
我遇到了类似的问题,我所做的只是将$event添加到我的html模板中的登录方法中。
<button ng-click="login(user,$event)"></button>
然后在我的js中,我调用了event.prventDefault();
.controller('HomeCtrl', function ($scope, $state, $http, $location) {
$scope.login = function (user, event) {
$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) {
event.preventDefault();
alert("redirect to main page");
$state.go("home");
} else if (response.data.status === 403) {
alert("Login or password incorrect");
} else {
alert("User not found");
}
});
};
})
$ionicHistory.goBack()
应该是最有效的方法。
相关文章:
- 无法在Ionic select中预先选择最后一个选项
- 如何在Ionic Android中将Javascript注入到web视图中
- Ionic和angularjs嵌套步骤应用程序
- 如何在Ionic2测试版中包含Ionic.io服务
- Ionic-item在导航栏中进行双向数据绑定
- SqlStorage Ionic 2作为服务/提供程序
- Ionic V1.3-标签-带条件的徽章样式<离子选项卡>
- 为什么当我尝试在Ionic中使用列表时会出现此JavaScript错误
- using LocalStorage ionic 2
- 将数据传递给由服务创建的Ionic模态
- OSM-离线查询我的IONIC/CORDOVA项目
- 如何从mac上完全删除Ionic和Cordova安装
- ionic幻灯片框中的每张幻灯片都有不同的HTML文件
- 未在angularJS和Ionic中加载模板
- 从Base64 Ionic编码和解码图像
- Ionic将firebase注入工厂,同时将控制器和服务保存在不同的文件中
- Ionic Android“;不支持重定向_ uri”;脸书
- Ionic:AngularJS变量未使用$scope更新DOM
- 使用Ionic 2进行POST调用
- Redirection Ionic