I am new to angular. I see across constructors,template,selector,etc. i have no idea. I know $scope,$rootscope, module and controller. With these I have written a code for ngFor.I believe before nfFor we had ngRepeat in angular1. please correct it.
<html ng-app="moduleA">
<head>
<title> Collections
</title>
<script src="angular.js"></script>
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-
bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<script
src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.20/angular.min.js">
</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js">
</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-
bootstrap/3.2.0/js/bootstrap.min.js"></script>
</head>
<body>
<script>
angular.module('moduleA')
.controller('SubjectController',function($scope,$rootscope){
$scope.todos = [
{ id: 1, title: 'Learn AngularJS', description: 'Learn,Live,Laugh AngularJS', done: true },
{ id: 2, title: 'Explore hibernate', description: 'Explore and use hibernate instead of jdbc', done: true },
{ id: 3, title: 'Play with spring', description: 'spring seems better have a look', done: false },
{ id: 4, title: 'Try struts', description: 'No more labour work..use struts', done: false },
{ id: 5, title: 'Try servlets', description: 'Aah..servlets stack seems cool..why dont u try once', done: false }
];
});
</script>
<div ng-controller="moduleA">
<table>
<thead>
<tr>
<th>#</th>
<th>Title</th>
<th>Description</th>
<th>Done?</th>
</tr>
</thead>
<tbody>
<tr ngFor="let todo of todos">
<td> {{todo.id}}</td>
<td> {{todo.title}}</td>
<td> {{todo.description}}</td>
<td> {{todo.done}}</td>
</tr>
</tbody>
</table>
</div>
2
Answers
You
cannot
usengFor
with angularjs, you can useng-repeat
to iterate over a collection.DEMO
As others mentioned,
ngFor
is not a part of AngularJSHowever, you can create function on
$rootScope
to simply generate a dummy array forngRepeat
as following:You can use it like this in your views: