2017-10-29 2 views
0

문제가 있습니다.angularjs ng-show가 http없이 작동하지 않습니다.

<div ng-controller='nav'> 
       <ul >    
        <li ng-show="sh" > 
         <a ui-sref="problems">name</a>       
        </li> 

      </div> 

내 컨트롤러는 다음과 같습니다 : 내 html 파일에서 나는 다음과 같은 내용이

app.controller('nav', function($scope, $state, $http){ 
     $(function(){   

      $scope.sh=true; 
      //$http.get('something'); 
     }); 
    });  

$http.get('something') 

주석

하는 경우를 NG 쇼가 작동하지 않습니다. 그러나 주석 처리를 제거하면 작업이 시작됩니다. 나는이 이유를 이해할 수 없다. 비슷한 문제가 있었습니까?

+2

컨트롤러에서 jquery 사용을 중지하십시오. anglejs 문서 나 어디서나 어디에서 anglejs 컨트롤러가 필요한지를 알았 으면'$ (function()'); $ (function()'또는 심지어 jQuery가 필요합니까? –

답변

0

을 사용할 수 있습니다 JQuery와 기능에 대한 필요가 없습니다.

<!DOCTYPE html> 
<html> 
<head> 
    <title></title> 
    <meta charset="utf-8" /> 
</head> 
<body> 
    <div ng-controller='nav'> 
     <ul> 
      <li ng-show="sh"> 
       <a ui-sref="problems">name</a> 
      </li> 
     </ul> 
    </div> 

    <script src="../lib/angular.js"></script> 
    <script> 
     var app = angular.module('app', []); 
     app.controller('nav', function ($scope, $state, $http) { 
       $scope.sh = true; 
       $http.get('something') 
     }); 
    </script> 
</body> 
</html> 

왜 내가 jquery 파트를 포함했는지 알지 못합니다. AngularJS 프로젝트에서는 jquery를 사용하지 않는 것이 좋습니다. AngularJS에서 거의 모든 것을 얻을 수 있습니다.

0

가 직접 코드를 아래이 시도 $scope.sh=true;

관련 문제