2016-08-31 1 views
0

同様の質問が見つかることは知っていますが、答えは私のために働いていません。私はログイン時に不正な資格情報に遭遇すると、例えば<h5>Your password is incorrect</h5>のようなhtmlを表示したい。したがって、このコードはコントローラ内部から「生きている」必要があります。私の見方は次のとおりです。angularjsコントローラから呼び出されたときにhtmlを表示

(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; 
      }); 
     }; 
    } 

})(); 

ありがとうございます!

答えて

1

これにはng-ifを使用できます。

はまず、お使いのコントローラに:あなたのhtmlで、その後

$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; 
    }); 
}; 

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

はそれがお役に立てば幸いです。

+0

あなたが信じられないです!出来た! – AvramPop

0

これを試すことができますか?

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

そして、あなたのコントローラ内:

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?? 

      }); 
     }; 
    } 
関連する問題