0

I have a problem. In my html file I have a following content:

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

            </div>

My controller is:

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

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

If

$http.get('something')

is commented, ng-show does not work. However, if I uncomment it, it starts to work. I cannot understand the reason of this. Did you have a similar problem?

quarandoo
  • 369
  • 4
  • 9
  • 2
    Stop using jquery in your controllers. You don't need `$(function()`. You just need `$scope.sh = true`. Where did you find, in the angularjs documentation or anywhere, that you needed your angularjs controller to use ``$(function()`, or even needed jQuery at all? – JB Nizet Oct 29 '17 at 10:09

2 Answers2

1

Try this below code.

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

I dont know why you included the jquery part. It is always good to not to use jquery in AngularJS projects. You will get almost all things in AngularJS one way or the another.

Rakesh Burbure
  • 1,045
  • 12
  • 27
0

There is no need for jquery function there you can directly use $scope.sh=true;

Gokulakrishnan M
  • 350
  • 4
  • 14