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