0

I am new to angularjs. I am trying to create a simple controller but i can't. Really need help.

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

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <title>Ionic Template</title>
    <script src="lib/ionic/js/ionic.bundle.js"></script>                                            
    <script src="cordova.js"></script>

    <!-- your app's js -->
    <script src="js/app.js"></script>
    <script src="js/controllers.js"></script>

    <script>
      function SimpleController($scope){
                              $scope.customers=[
                                          {name:'Djo', city:'johannesburg'},
                                          {name:'tri',city:'vaal'},
                                          {name:'stone',city:'pretoria'},
                                          {name:'loick',city:'durban'}
                                        ];
                             }

                </script>
<body >
    <div class="container" ng-controllers="SimpleController">   
       <ul >
           <!-- we are accessing thescope -->
            Name: <input type="text" data-ng-model="name" /> {{ name}} 
           <li ng-repeat="cust in customers"> {{ custt.name}} - {{cust.city}} </li>
       </ul>  
    </div>  
   </body>
</html>
Rabi
  • 2,210
  • 17
  • 18
trinidado
  • 31
  • 9

2 Answers2

1

Global controllers were disabled in angularjs 1.3 +

<html ng-app="ionicApp">
<body>
<div ng-controller="SimpleController">

</div>
</body>
<script>
     angular.module("ionicApp",[])
            .controller("SimpleController", [$scope, function($scope){
                 // your code here
            }])
</script>
Prasanth Bendra
  • 31,145
  • 9
  • 53
  • 73
  • Getting an error when using ng-controller in angularjs ver 1.3.0 also not working Sir – trinidado Sep 30 '15 at 02:53
  • I really can't figure out what is the error. On the browser, it's only showing the text box, {{name}} and at the bottom, this {{cust.name}}{{cust.city}} just as they appear on the code. it's really weird coz normally all of the solutions you guys have given me should work... – trinidado Sep 30 '15 at 08:07
  • @trinidado Please check you your firebug console for errors – Prasanth Bendra Sep 30 '15 at 08:48
  • it s still telling me that the scope is not defined. don't know y – trinidado Sep 30 '15 at 11:05
  • My bad, change this line `.controller("SimpleController", [$scope, function(){` to `.controller("SimpleController", [$scope, function($scope){` – Prasanth Bendra Sep 30 '15 at 11:23
0

Solved! it was as simple as this:

instead of

<script>
     angular.module("ionicApp",[])
            .controller("SimpleController", [$scope, function(){
                 // my code here
            }])
</script>

i just passed the $scope as a parameter in the function

<script>
     angular.module("ionicApp",[])
            .controller("SimpleController",function($scope){
                 // my code here
            })
</script>

Thanks guys for your help

trinidado
  • 31
  • 9