AngularJS Login form with ng-click not working

前端 未结 2 1183
余生分开走
余生分开走 2021-01-28 22:10

I wrote a basic login form in this plunk http://plnkr.co/edit/xQEN1ZNN5ZEw1CSwNw97?p=preview (click on the red Log into Dashboard button on the Home route).

However for

相关标签:
2条回答
  • 2021-01-28 22:26

    The controller change I applied is:

    angular.module('routerApp').controller('LoginCtrl', function ($rootScope, $scope) {
    
        $scope.loginUser = function () {
            $scope.dataLoading = true;
            //loginService.authUser(login.user, login.password);  // TO DO !!!
        };
        $scope.test = function () {
            var test = true;
        };
    })
    

    and in the template I removed login. from the ng-if and ng-submit.

    Here is a working plunks.

    0 讨论(0)
  • 2021-01-28 22:36

    for some odd reason (perhaps ui-router versioning) the controllerAs is not working.

    Diana´s answer is valid, but it doesn´t use the controlleras syntax. If you still want to use it, change the ui-router setting to:

    .state('login', {
            url: "/login",
            templateUrl: "login-form.html",
            controller: 'LoginCtrl as login',
        })
    

    That should do the trick ;)

    Check it out: http://plnkr.co/edit/OCqNexVeFFxt4kUuEVc1?p=preview

    0 讨论(0)
提交回复
热议问题