2015-12-12 28 views
1

我試圖按照ng-show和ng-hide的工作方式。我希望在REST調用成功時顯示錶單,如果調用返回空值,則顯示錯誤消息。AngularJS:ng-show usage

我還通過AngularJS: ng-show/ng-hide

,但還是不太明白他們究竟是如何工作去了。誰能幫忙?

+0

代碼嗎?一名運動員會更好。 –

回答

1

使用承諾

 var promise = service.Method(); 
     promise.then(function(response) { 
      //Show 
      $scope.elementVisibility = true; $scope.errorMsg = false; 
     }, function(reason) { 
      // Hide 
      $scope.elementVisibility = false; $scope.errorMsg = true; 
     }); 


    <form ng-show="elementVisibility"></form> 
    <div ng-hide="errorMsg"></div>