我正在使用 Firebase后端使用离子应用。我的问题是 ng-click="loginUser(user)"
没有解雇。
控制台正在显示来自Auth.$onAuthStateChanged()
的 Signed Out ,而不是其他内容。单击该按钮不会显示Clicked!
日志。
这是我的example日志。
这是登录页面:
<ion-view title="Login" hide-nav-bar="true" nav-transition="none" id="page8" style="background-color:#FFC900;">
<ion-content padding="true" class="manual-ios-statusbar-padding">
<div id="login-container6">
<div>
<img src="img/PqmLrUhgT9WL19CElH4P_skc_logo.png" width="85" height="auto" style="display: block; margin-left: auto; margin-right: auto;">
</div>
<div class="spacer" style="height: 40px;"></div>
<form id="login-form5" class="list">
<label class="item item-input" id="login-input5">
<span class="input-label">Email</span>
<input type="email" placeholder="" ng-model="user.email">
</label>
<label class="item item-input" id="login-input6">
<span class="input-label">Password</span>
<input type="password" placeholder="" ng-model="user.password">
</label>
<div class="spacer" style="height: 40px;"></div>
<button id="login-button3" class="button button-light button-block" ng-click="loginUser(user)">Log in</button>
</form>
</div>
</ion-content>
这里是登录控制器:
.controller('loginCtrl', ['Firebase', 'Auth', '$stateParams', '$state', '$ionicModal', '$location', function (Firebase, Auth, $scope, $stateParams, $state, $ionicModal, $location) {
Auth.$onAuthStateChanged(function (authData, $location) {
if (authData) {
console.log("Signed in as :", authData.email);
$scope.loggedInUser = authData;
$state.go('tabsController.search')
} else {
console.log("Signed out");
$scope.loggedInUser = null;
}
});
// Log in
$scope.loginUser = function (user) {
console.log('Clicked!');
if ($scope.isIncorrectValue(user.email) || $scope.isIncorrectValue(user.password)) {
$scope.error = "You filled out the form wrong...";
} else {
Auth.$signInWithEmailAndPassword(user.email, user.password)
.then(function (authData) {
$scope.loggedInUser = authData;
console.log('AuthData =' + authData);
}).catch(function (error) {
$scope.error = "" + error;
});
}
}
}])
编辑 - 这是路由:
angular.module('app.routes', [])
.config(function ($stateProvider, $urlRouterProvider) {
... // Other Pages
.state('login', {
url: '/login',
templateUrl: 'templates/login.html',
controller: 'loginCtrl'
})
... // Other Pages
$urlRouterProvider.otherwise('/login')
});
答案 0 :(得分:0)
我的问题出在 loginCtrl 声明中。我没有$scope
并且有$state
两次,没有错误。