angularjs ng show在没有http get的情况下无法工作

angularjs ng show在没有http get的情况下无法工作,angularjs,http,get,ng-show,angularjs-ng-show,Angularjs,Http,Get,Ng Show,Angularjs Ng Show,我有个问题。在我的html文件中,我有以下内容: <div ng-controller='nav'> <ul > <li ng-show="sh" > <a ui-sref="problems">name</a>

我有个问题。在我的html文件中,我有以下内容:

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

            </div>
如果

$http.get('something')

已注释,ng show不起作用。但是,如果我取消注释它,它就会开始工作。我不明白这是为什么。你有类似的问题吗

这里不需要jquery函数,您可以直接使用$scope.sh=true

试试下面的代码

<!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中的几乎所有内容。

停止在控制器中使用jquery。您不需要$function。您只需要$scope.sh=true。在angularjs文档或任何地方,您在哪里发现需要angularjs控制器使用“`$function`,甚至需要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>