What is the wrong in the below code? I can't find the error

Posted by Nandkishorrech under JavaScript on 1/28/2015 | Points: 10 | Views : 1480 | Status : [Member] | Replies : 1
What is the wrong in the below code? I can't find the error.Data is not binding to the list.


<!DOCTYPE html>
<html data-ng-app>
<head>
<title></title>
</head>
<body>

<div data-ng-controller="SimpleController">
<h3>Controller Example</h3>
<ul>
<li data-ng-repeat="cust in customers">
{{cust.name}} - {{cust.code}}
</li>
</ul>

</div>
<script src="angular.min.js"></script>
<script>
function SimpleController($scope) {
$scope.customers = [
{
name: 'JQuery', code: 'JQ'
},
{
name: 'JScript', code: 'JS'
},
{
name: 'CSharp', code: 'C#'
}
];
}
</script>
</body>
</html>



Regards,
Nanda Kishore.CH




Responses

Posted by: kgovindarao523-21772 on: 1/28/2015 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,
create angular module and specify in html, and register controller to that module.
Here is the code:
<script> 

window.onload=function(){
var app=angular.module('test');
app.controller('SimpleController',SimpleController);
};
function SimpleController($scope) {
$scope.customers = [
{
name: 'JQuery', code: 'JQ'
},
{
name: 'JScript', code: 'JS'
},
{
name: 'CSharp', code: 'C#'
}
];
}
</script>

In html replace below tag:
<html data-ng-app='test'> 


it will work fine.

Thank you,
Govind

Nandkishorrech, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response