Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

In below code uncommented part is not working ("Third method").

All page doesn't work. Not a part of it..

But when I use the "Second method" it's working..

<html data-ng-app="demoApp">
   <head>
        <title>...</title>
   </head>
   <body>
      <div class="container" data-ng-controller="SimpleController"> 
         <h3>Using controller data</h3>
         Name: <input type="text" data-ng-model="personTxt"/> {{personTxt}}
         <ul>
           <li data-ng-repeat="person in customers | filter:personTxt | orderBy:'city'">{{person.name}} . {{person.city}}</li>
         </ul>
      </div>

      <script src="angular.min.js"> //Should be at the starting of the script</script>
      <script>
         var demoApp = angular.module('demoApp', []);       
         /* Third method */     
         var controllers = {};      
         controllers.SimpleController =
         function ($scope) {
            $scope.customers = [
               {name:'Sahan Chamika Munasinghe', city:'Kaburupitiya'},
               {name:'Nuwan Sachinthana', city:'Walgama'},
               {name:'Diunuge Buddhika Wijesinghe', city:'Matara'}
            ];

            $scope.personTxt = "My Name";
         });

         demoApp.controller(controllers);
       </script>
   </body>
</html>

Second type

/* Second method */
/*
   demoApp.controller('SimpleController', 
   function ($scope) {
      $scope.customers = [
         {name:'Sahan Chamika Munasinghe', city:'Kaburupitiya'},
         {name:'Nuwan Sachinthana', city:'Walgama'},
         {name:'Diunuge Buddhika Wijesinghe', city:'Matara'}
      ];            
      $scope.personTxt = "My Name";
   });

   demoApp.controller('SimpleController', SimpleController);
*/
share|improve this question

1 Answer 1

up vote 0 down vote accepted

You have an additional trailing close paren on the last line of the definition:

controllers.SimpleController = 
                function ($scope)
                {
                    $scope.customers = [
                        {name:'Sahan Chamika Munasinghe', city:'Kaburupitiya'},
                        {name:'Nuwan Sachinthana', city:'Walgama'},
                        {name:'Diunuge Buddhika Wijesinghe', city:'Matara'}
                    ];

                    $scope.personTxt = "My Name";
                });

Get rid of the last ) before the semicolon, and everything should work

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.