1
<!DOCTYPE html>
<html data-ng-app="myApp">
<head>
    <title></title>
    <script src="Script/angular.js"></script>
</head>
<body data-ng-controller="SimpleController">

// controller defined //

        <ul>
            <li data-ng-repeat="data in customers">

// data is not access controller

             {{data.name}}-{{data.city}}
             </li>
        </ul>
    </div>

/Is this way is correct to define controller/

    <script>
        function SimpleController($scope) {
                 $scope.customers = [
                 { name: 'alok ', city: 'azam' },
                 { name: 'muku', city: 'lko' },
                 { name: 'rajat', city: 'jungle' }

                 ];}
                 </script>
</body>
</html>
pushpanshu
  • 13
  • 1
  • 4
  • angularjs version ? if its 1.3 or above please see this http://stackoverflow.com/questions/26646941/getting-an-error-when-using-ng-controller-in-angularjs-ver-1-3-0/26647015#26647015 – Kalhan.Toress Apr 07 '15 at 16:24

1 Answers1

1

I've rewritten your html a bit and it works now. You have to define module called myApp and have to use controller directive to define controller in the module. Please look at the sample I've added http://jsfiddle.net/uv0gw4kL/2/

<!DOCTYPE html>
<html ng-app="myApp">
<head>
    <title></title>
</head>
<body ng-controller="SimpleController">

  <ul>
    <li ng-repeat="data in customers">
      {{data.name}}-{{data.city}}
  </li>
</ul>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular.js"></script>
    <script type="text/javascript">
        angular.module('myApp', [])
        .controller('SimpleController', function ($scope) {
            $scope.customers = [
            { name: 'alok ', city: 'azam' },
            { name: 'muku', city: 'lko' },
            { name: 'rajat', city: 'jungle' }
            ];
        });
    </script>
</body>
</html>

More about angular controllers here http://www.w3schools.com/angular/angular_controllers.asp

You can also use allowGlobals feature from controller provider https://docs.angularjs.org/api/ng/provider/$controllerProvider but it's not recommended.

Oleg
  • 1,100
  • 2
  • 11
  • 16