ng-repeat does not show me the list

0

I'm starting to learn Angular. make a small example and show me the list:

HTML and JS:

var app = angular.module(
	'flapperNews',
		[]
);

app.controller(
	'MainCtrl', 
	
	[
		'$scope',
		function($scope) {
  			$scope.test = 'Hello wrorld!';
  			$scope.post = [
  				'post 1',
  				'post 2',
  				'post 3',
  				'post 4',
  				'post 5'
  			];
		}
	]
);
<html>
  <head>
    <title>My Angular App!</title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
    <script src="app.js"></script>
  </head>
  <body ng-app="flapperNews" ng-controller="MainCtrl">
      <div>
        {{post}}
      </div>
  </body>
</html>

But if I add the "np-repeat", it does not work :( This is the code (same JS):

<html>
  <head>
    <title>My Angular App!</title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
    <script src="app.js"></script>
  </head>
  <body ng-app="flapperNews" ng-controller="MainCtrl">
      <div ng-repeat="post in posts">
        {{post}}
      </div>
  </body>
</html>

I'm following this tutorial ( link ), it works as it is, I do not know what my mistake will be

    
asked by MAURICIO SILVA CAVIEDES 13.09.2017 в 19:26
source

1 answer

1

It is because you are calling the ng-repeat wrong so that it works simply change $scope.post by $scope.posts , first go the name you want to give to your ng-repeat and then the name of the object

var app = angular.module(
	'flapperNews',
		[]
);

app.controller(
	'MainCtrl', 
	
	[
		'$scope',
		function($scope) {
  			$scope.test = 'Hello wrorld!';
  			$scope.posts = [
  				'post 1',
  				'post 2',
  				'post 3',
  				'post 4',
  				'post 5'
  			];
		}
	]
);
<html>
  <head>
    <title>My Angular App!</title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
    <script src="app.js"></script>
  </head>
  <body ng-app="flapperNews" ng-controller="MainCtrl">
      <div ng-repeat="post in posts">
        {{post}}
      </div>
  </body>
</html>
    
answered by 13.09.2017 / 19:42
source