【问题标题】:Ionic ng-click not firing离子 ng-click 不触发
【发布时间】:2017-02-26 07:43:00
【问题描述】:

我正在使用 Firebase 后端Ionic 应用。我的问题是 ng-click="loginUser(user)" 没有触发。

控制台显示来自Auth.$onAuthStateChanged()已注销,没有其他内容。单击该按钮不会显示Clicked! 日志。

这是我的Console 日志。

这是我的登录页面

<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')

});

【问题讨论】:

  • 你把ng-controller放了吗?
  • 您是否已将 loginCtrl 分配给您的视图?
  • 我有,我正在从 loginCtrl 获取已注销的控制台日志。
  • 您在视图中使用了用户模型。您是否在控制器中分配了 $scope.user 模型?
  • 你可以留下你为那个模板声明控制器的代码吗?

标签: javascript angularjs ionic-framework firebase firebase-authentication


【解决方案1】:

我的问题出在 loginCtrl 声明中。我没有$scope$state 两次,没有错误。

【讨论】:

    猜你喜欢
    • 2017-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-19
    • 2017-03-04
    • 1970-01-01
    相关资源
    最近更新 更多