Angularjs工厂捕获功能不适用范围

时间:2015-10-01 15:31:16

标签: angularjs

我将Angular从版本1.3.14升级到1.4.5

当以下代码进入loginService工厂的then函数时,它将值应用于范围。进入catch / error函数时,它不适用于范围。它在1.4.5中是否有效?

    (function () {
        'use strict';
        var loginController = angular.module('test.login.controller', ['ngMessages', 'ui.bootstrap']);

        loginController.controller('LoginController', function (securityService, $state, $scope, loginService, $log, $http, EXT_API) {

            securityService.clearCredentials();

            var loginCtrl = this;
            loginCtrl.credentials = {};
            loginCtrl.loginButton = 'Submit';
            loginCtrl.cancelButton = 'Cancel';
            loginCtrl.heading = 'Test Engine';
            loginCtrl.usernameLabel = 'User Name';
            loginCtrl.passwordLabel = 'Password';
            loginCtrl.showAlertMessage = false;
            loginCtrl.alertMessage = '';

            loginCtrl.login = getLogin;

            function getLogin(credentials) {
                $http.post(EXT_API + '/rest/login/authenticate/123456789', JSON.stringify({credentials: credentials}))
                        .then(function (response) {
                            $log.info('Login successful');
                            loginCtrl.showAlertMessage = true;
                            loginCtrl.alertMessage = 'Valid User Name and Password';

                        }, function (result) {
                            $log.info('Login Failed');
                            loginCtrl.showAlertMessage = true;
                            loginCtrl.alertMessage = 'Invalid User Name or Password';
                        });
            };

        });
    })();

在登录页面上,单击提交时,表单设置如下。

<form class="form-horizontal" name="loginForm" ng-submit="loginCtrl.login(loginCtrl.credentials)" novalidate>
        <input type="text" class="form-control" id="username" name="username" placeholder="User Name" ng-model="loginCtrl.credentials.username" required>
        <input type="password" class="form-control" id="password" name="password" placeholder="Password" ng-model="loginCtrl.credentials.password" required>
</form>

1 个答案:

答案 0 :(得分:0)

在应用程序中进行了大量搜索之后,我发现了一个处理某些HTTP错误代码的拦截器。

移除拦截器后一切都很完美。需要进行一些重构才能使页面正常工作。

由于