I am new to angular.js just started learning, i want to Display the array defined in the Controller, But When I am trying to Display Its Showing empty page. I know if i change the ng-repeat=post in post1 to ng-repeat=post in posts" it ll work. But i want show the Error either in the Console or in the Browser. Please Can anybody help me.
var mainapp = angular.module('mainApp', []);
mainapp.controller('control', function ($scope) {
$scope.posts = [
{title: 'post 1', upvotes: 5},
{title: 'post 2', upvotes: 2},
{title: 'post 3', upvotes: 15},
{title: 'post 4', upvotes: 9},
{title: 'post 5', upvotes: 4}
];
});
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.min.js"></script>
</head>
<body ng-app="mainApp" ng-controller="control">
<div ng-repeat="post in post1 | orderBy:'upvotes'">
<p>{{post.title}}-upvotes {{post.upvotes}}</p>
</div>
</body>
</html>
$scope
is an object and in view all are scope property. If property doesn't exists in$scope
, it'll be added. It won't throw error.