Reputation: 448
I am newbie in angular trying to loop through an array. I am not getting an error when i run the code below but I am not getting any output from the array/property customers.
<div class="col-sm-4 col-sm-push-4 margin-top-30">
<div class="container" data-ng-controller="VideoController">
<input type="text" ng-model="name" /> {{ name }}
<h3>Looping with the ng-repeat Directive</h3>
<ul>
<li data-ng-repeat="cust in customers | filter:name | orderBy:city">{{ cust.name }} - {{ cust.city }}</li>
</ul>
</div>
<script src="scripts/angular.js"></script>
<script>
function VideoController($scope) {
$scope.customers= [
{name:'John Smith', city:'Phoenix'},
{name:'John Doe', city:'San Fransisco'},
{name:'Test Doe', city:'CPT'}
];
}
</script>
</div>
Can someone please point were im going wrong in the code
Upvotes: 0
Views: 46
Reputation: 17064
If you don't already have one, add an Angular app to your code:
var myApp = angular.module('myApp', [])
Which you need to use in your HTML:
<div ng-app="myApp">
Now, anything inside that div (you can place it on other elements such as the body) will be in the scope of your app. If you want to use a controller, you have to register that to the app if you're using a version of angular that is >= 1.3:
myApp.controller('VideoController', VideoController);
Upvotes: 2