What am i doing wrong here, I am new to angular, its showing the error above, here is my code
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.js"></script>
<script>
function simpleController($scope){
$scope.customers=[
{name:'Alphy Poxy',city:'Mbita'},
{name:'Kibaki Watson',city:'Kikuyu'},
{name:'John Legend',city:'Lake'},
{name:'Sony',city:'HB'}
];
}
</script>
</head>
<body>
<div class="container-fluid" ng-controller="simpleController">
Name: <input type="text" ng-model="name"/>
<ul>
<li ng-repeat="coders in customers | filter:name | orderBy:'name'">{{coders.name}}-{{coders.city}}</li>
</ul>
</div>
</body>
You haven't created properly your controller. Please see the following snippet.
var myApp = angular.module('myApp',[]);
myApp.controller('simpleController', ['$scope', function($scope) {
$scope.customers=[
{name:'Alphy Poxy',city:'Mbita'},
{name:'Kibaki Watson',city:'Kikuyu'},
{name:'John Legend',city:'Lake'},
{name:'Sony',city:'HB'}
];
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div class="container-fluid" ng-app="myApp" ng-controller="simpleController">
Name: <input type="text" ng-model="name"/>
<ul>
<li ng-repeat="coders in customers | filter:name | orderBy:'name'">{{coders.name}}-{{coders.city}}</li>
</ul>
</div>
Or at least you need to pub ng-app directive in parent html tag please see demo below
function simpleController($scope) {
$scope.customers = [{
name: 'Alphy Poxy',
city: 'Mbita'
}, {
name: 'Kibaki Watson',
city: 'Kikuyu'
}, {
name: 'John Legend',
city: 'Lake'
}, {
name: 'Sony',
city: 'HB'
}];
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app>
<div class="container-fluid" ng-controller="simpleController">
Name:
<input type="text" ng-model="name" />
<ul>
<li ng-repeat="coders in customers | filter:name | orderBy:'name'">{{coders.name}}-{{coders.city}}</li>
</ul>
</div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With