Join the Stack Overflow Community
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I am new to AngularJS and stuck with an output.

Here is the code snippet:

<html ng-app>  
<body>  
<div class="container" data-ng-controller="simpleController">  
    <ul>
        <li ng-repeat="cust in customers | orderBy:'name'">
        {{ cust.name | uppercase }} - {{ cust.city | lowercase }} - {{                   cust.balc | currency }}
        </li>
    </ul>
</div>  
<script>
    angular.module("app",[]).controller("simpleController",function($scope){  
        $scope.customers = [  
                           { name: 'Dave', city: 'Jaipur', balc: '500'},  
                           { name: 'Shruti', city: 'Toronto', balc: '1000'},  
                           { name: 'Rishu', city: 'Phoenix', balc: '2000'},  
                           { name: 'Shweta', city: 'California',balc:'3000'}
                           ];  
    }  
</script>
</body>
</html>

Can someone tell me what is wrong with my code. I have put single quotes before div tag and li tag because it wasnt displaying on stackoverflow otherwise.

share|improve this question
    
Can you place a JSFiddle Link? – Shankar Shastri Aug 22 at 11:15
    
how do we do that? – ShrutiK Aug 22 at 11:20

The answer above is right, but I guess you want to use them in ng-repeat, so you can use whatever name you want in the expressions, this name will be the current element of your array. You have to wrap it like this:

`<div ng-repeat="cust in customers">{{ cust.name | uppercase }} - {{ cust.city | lowercase }} - {{ cust.balc | currency }}</div>`
share|improve this answer
    
please check the edited code. – ShrutiK Aug 22 at 11:21
    
I made a working fiddle – Julsy Aug 22 at 11:30
    
Actually, you can use it the way you wrote it but: 1. You hadn't closed the controller function on the line before the closing </script> tag and after the }. You should add );. 2. And you should add a value to the <html ng-app> like so <html ng-app='app'> – Julsy Aug 22 at 11:38
    
okk.. your code worked on my system. Apart from the other problems, it wasnt working because I hadn't add ['$scope', function($scope) – ShrutiK Aug 22 at 12:06
    
That was my suggestion in the fiddle.Because -> from Angular documentation: Controllers are "classes" or "constructor functions" that are responsible for providing the application behavior that supports the declarative markup in the template. The recommended way of declaring Controllers is using the array notation: . You can read more here: docs.angularjs.org/guide/controller – Julsy Aug 22 at 12:20

In ng-app you are not passing the module name. Please Find The JSFiddle Link I have Updated It with code.

HTML Code
<html ng-app="app">

  <body>
    <div class="container" data-ng-controller="simpleController">
      <ul>
        <li ng-repeat="cust in customers | orderBy:'name'">
          {{ cust.name | uppercase }} - {{ cust.city | lowercase }} - {{ cust.balc | currency }}
        </li>
      </ul>
    </div>

  </body>

</html>

JS Code
angular.module("app", []).controller("simpleController", function($scope) {
  $scope.customers = [{
    name: 'Dave',
    city: 'Jaipur',
    balc: '500'
  }, {
    name: 'Shruti',
    city: 'Toronto',
    balc: '1000'
  }, {
    name: 'Rishu',
    city: 'Phoenix',
    balc: '2000'
  }, {
    name: 'Shweta',
    city: 'California',
    balc: '3000'
  }];
})

http://jsfiddle.net/rs64h0jz/

share|improve this answer
    
I think that is not necessary. I am passing the controller name in ng-controller. – ShrutiK Aug 22 at 11:24

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.