0

I'm beginner in angularJs and I have this simple and maybe stupid problem, can't connect simple controller to view:

<!DOCTYPE html>
<html ng-app>
<head>
    <title></title>
</head>
<body>
    <div ng-controller="SimpleController">
        NAME:
        <input type="text" name="name" ng-model="name" />
        <br/>
        <ul>
            <li ng-repeat="cust in customers | filter:name | orderBy:'city'">{{cust.name | uppercase}} - {{cust.city}}</li>
        </ul>
    </div>
    <script src="js/angular.min.js" type="text/javascript"></script>
    <script>
        function SimpleController($scope){
            $scope.customers=[{name:'Amelie',city:'Tbilisi'},{name:'Jani', city:'New York'}];
        }
    </script>

</body>
</html>

So, can anyone explain what i'm doing wrong?

Anik Islam Abhi
  • 25,137
  • 8
  • 58
  • 80
Ketevan Toria
  • 109
  • 1
  • 14
  • You have the model name and the field name in object of equals, may be a problem with that. Change the name of the model – Saahon Dec 22 '15 at 10:50

2 Answers2

2

From angular vs1.3.x you have to bind controller with module in order to use.

Like this

angular
   .module("app",[])
   .controller("SimpleController",function($scope){
     $scope.customers=[{name:'Amelie',city:'Tbilisi'},{name:'Jani', city:'New York'}];
})

Add module name in html

<html ng-app="app">

JSFIDDLE

Anik Islam Abhi
  • 25,137
  • 8
  • 58
  • 80
1

First, you didn't reference the angularjs script in your page.

Then depends on your Angular version (>= 1.3), you have to create a module and register the controller inside.

angular.module("myApp",[])
.controller("SimpleController",function($scope){
    $scope.customers=[{name:'Amelie',city:'Tbilisi'},{name:'Jani', city:'New York'}];
});

<html data-ng-app="myApp">