chris chris - 6 months ago 13
HTML Question

Custom Controller Not working in angularjs

<html ng-app>
<head>
</head>
<body data-ng-controller="Myfunc">
<ol type="i">
<li data-ng-repeat="c in cust | filter:name"> {{ c.name | lowercase}} - {{c.city | lowercase}}</li>
</ol>
<script src="angular.js"></script>
<script>

function Myfunc($scope)
{
$scope.cust=[
{name:'grimer',city:'ambernath'},
{name:'primer',city:'goregaon'}
];
}
</script>
</body>
</html>


custom controller not working in angularjs
don't know whether the custom script is working or not or something else

Answer

I have updated your code and it is now working:

<html>

<head></head>

<body>

<div ng-app>
  <div data-ng-controller="Myfunc">
    <ol type="i">
      <li data-ng-repeat="c in cust | filter:name"> {{ c.name | lowercase}} - {{c.city | lowercase}}</li>
    </ol>

    <script src="angular.js"></script>
    <script>
      function Myfunc($scope) {
        $scope.cust = [{
          name: 'grimer',
          city: 'ambernath'
        }, {
          name: 'primer',
          city: 'goregaon'
        }];
      }
    </script>

  </div>
</div>
</body>

</html>

What I did is to move ng-app to a div and the data-ng-controller="Myfunc" to a div inside it.

You can find the working version at this js_fiddle url.

Comments