我在登錄控制器兩種功能兩個功能都 實現登錄目的, 在這個控制器!scope.isLoggedIn條件satistified需要檢查裏面的狀態。 我需要永久登錄在應用程序,所以我存儲用戶名和密碼credientical在本地sessionStorage 只要值在localStorage中可用我需要執行自動登錄功能, 我檢查localStorage數據可用或不在if條件 如果用戶名和密碼是localStorage中可用我需要執行automaticLoginUser函數 如果不是無需執行自動登錄功能 每當我嘗試執行該automaticLoginUser函數獲取錯誤 TypeError:scope.automaticLoginUser不是函數錯誤。 謝謝先進..!如何調用內部的控制器功能於angularjs
app.controller('LoginCtrl', ['$scope',
'userService', '$state', '$rootScope','BackendService', 'CartService',
function(scope, userService, $state, rootScope, BackendService, CartService) {
scope.user = {};
scope.isLoggedIn = false;
scope.userId = CartService.getuserId();
scope.userPassword = CartService.getuserPassword();
if (!scope.isLoggedIn) {
console.log('in side isLoggedIn');
if (scope.userId !== undefined && scope.userPassword !== undefined) {
var loginId = scope.userId;
var password = scope.userPassword;
scope.user.loginId = loginId;
scope.user.password = password;
console.log('after user' + scope.user);
var user = scope.user;
scope.automaticLoginuser(user);
}
scope.automaticLoginuser = function(user) {
alert("Inside automaticLoginuser");
CartService.saveuserId(scope.user.loginId);
CartService.saveuserPassword(scope.user.password);
userService.loginuser(user)
.then(function(response) {
scope.userUuid = response.data.userUuid;
userService.setuserUuid(scope.userUuid);
if (response.data.status === 'success') {
CartService.saveFuuid(scope.fuuid);
$state.go("app.userHome");
} else {
$state.go("app.login");
}
});
};
scope.loginuser = function(user) {
CartService.saveuserId(scope.user.loginId);
CartService.saveuserPassword(scope.user.password);
userService.loginuser(user)
.then(function(response) {
scope.userUuid = response.data.userUuid;
userService.setuserUuid(scope.userUuid);
if (response.data.status === 'success') {
$state.go("app.userHome");
} else {
$state.go("app.login");
}
});
};
}
]);
我想你是在調用scope.automaticLoginuser(user);在宣佈之前 – Gerard