0
我下面在app.js
$scope.init = function()
{
if(localStorage.getItem("id")!=null && localStorage.getItem("pass")!=null)
{
alert(localStorage.getItem("id")+" "+localStorage.getItem("pass"));
var id=localStorage.getItem("id");
var pass=localStorage.getItem("pass");
$http({method: 'GET', url: site+'/login-web.php?txt_email='+id+'&txt_password='+pass}).
success(function(data, status, headers, config)
{
if(data=='error')
navigator.notification.alert("Wrong username or password.",null,"Attention.!","Try Again.!");
else
{
localStorage.setItem("id", id);
localStorage.setItem("pass", password);
alert("fire");
$scope.ons.navigator.pushPage('dashboard.html',{title : 'title'});
}
}).
error(function(data, status, headers, config)
{
alert("Please check Mobile Data.");
// called asynchronously if an error occurs
// or server returns response with an error status.
});
}
},
初始化函数,我火的init从
<body ng-controller="AppController" ng-init="init()">
我要赞如果我第一次登录,那么我需要登录,我需要登录并存储id,并通过localstorage,每次应用程序加载时,init方法都会触发,我检查id并从localstorage和fire服务器方法传递,以检查id并传递它正确的登录是自动完成的。
我使用的是phonegap + onsenui + angular js。
问题是从init方法
$scope.ons.navigator.pushPage('dashboard.html',{title : 'title'});
没有重定向到dashborad。
感谢您的答复。但是init()被调用并且value从localstorage成功获取,但页面没有重定向到dashboard.html – 2014-10-06 17:03:05
@PareshGami我认为这是因为你的http服务中有承诺。我建议通过我的答案更新你的http数据。然后将其注入您的控制器。它应该这次工作。祝你好运。 – khemry 2014-10-07 04:44:26
谢谢。你正在改变app.factory吧?但你能解释一下它的工作情况和来自init的调用吗? – 2014-10-07 17:20:38