0

I know that similar questions can be found, but no answer worked for me. I want to show a html, for example <h5>Your password is incorrect</h5> when i encounter bad credentials at login. So this code should be "made alive" from inside the controller. Here's how mine looks like:

( function () {
    'use strict';

    angular
        .module( 'app.home' )
        .controller( 'ploginController', ploginController );

    ploginController.$inject = [ '$scope', '$location', '$state', '$http' ];

    /* @ngInject */
    function ploginController( $scope, $location, $state, $http ) {

        $scope.submit = function () {
            $http.post( '/api/v1/person/login', $scope.add, {
                headers: {
                    'Content-Type': 'application/json'
                }
            } ).then( function ( respSucc ) {
                $state.go( 'layout.listcampaigns' );
                return respSucc;
            }, function ( respErr ) {
//i think code revealing method should be HERE, but how??
                return respErr;
            } );
        };
    }

} )();

Thanks in advance!

2 Answers 2

1

You can use ng-if for that.

First, in your controller:

$scope.loginIncorrect = false;

...

$scope.submit = function () {
    $http.post( '/api/v1/person/login', $scope.add, {
        headers: {
            'Content-Type': 'application/json'
        }
    } ).then( function ( respSucc ) {
        $scope.loginIncorrect = false;
        $state.go( 'layout.listcampaigns' );
        return respSucc;
    }, function ( respErr ) {
        $scope.loginIncorrect = true;
        return respErr;
    } );
};

then in your html:

<h5 ng-if="loginIncorrect">Your password is incorrect</h5>

Hope it helps.

Sign up to request clarification or add additional context in comments.

Comments

0

Can you try this??

<h5 ng-show="showError">Your password is incorrect</h5>

And within your controller:

  function ploginController( $scope, $location, $state, $http ) {
        $scope.showError =false;
        $scope.submit = function () {
            $http.post( '/api/v1/person/login', $scope.add, {
                headers: {
                    'Content-Type': 'application/json'
                }
            } ).then( function ( respSucc ) {
                 $scope.showError =false;
                $state.go( 'layout.listcampaigns' );
                return respSucc;
            }, function ( respErr ) {
                  $scope.showError =true;
//i think code revealing method should be HERE, but how??

            } );
        };
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.