0

I'm tring to repeat an array in the html

html:

   

<div class="personWrapper" ng-repeat="message in messages">
		<p>{{message}}</p>
	</div>

js:

var app = angular.module('matcherApp', [ "ngRoute", "ngStorage" ]);

app.config(function($routeProvider) {
	$routeProvider.when('/Messages', {
		templateUrl : 'menu/messages.php',
		controller : 'messagesController'
	})
});
    app.controller('messagesController', function($scope, $localStorage) {

	console.log("im in messages page!!!");
	var messagesUsers = [];
	$.post("db.php", {
		'messagesWindow' : "messagesWindow",
		'myProfileId' : JSON.parse(localStorage.getItem("myProfileDetails")).id
	}, function(data) {
		data = $.parseJSON(data);
		angular.forEach(data, function(key, value) {
			angular.forEach(key, function(key2, value2) {
				messagesUsers.push(key2.Name);
			});
		});

		console.log(messagesUsers);
		$scope.messages = messagesUsers;
	}).fail(function() {
		alert("error bringing messages data");
	});

});

the console.log show me:

im in messages page!!! ["a","b"]

that works with all different controllers in the same app. its not showing me on the dom any loop. what am i doing wrong? thanks.

5
  • 1
    what is your question/problem? Commented Nov 10, 2015 at 9:50
  • its not show me on the dom any loop.... Commented Nov 10, 2015 at 10:21
  • Can you show your controller code? Commented Nov 10, 2015 at 10:22
  • Please post more of your html and controller-code Commented Nov 10, 2015 at 10:24
  • i updated the question to the full code... the problem is not in the route or in the post, becouse i have more pages that works fine. and the post bring me back exactly the data i need... ( iprint it also to the console) ,do you know what i am doing wrong? Commented Nov 10, 2015 at 21:29

2 Answers 2

2

Works for me! Look

var app = angular.module('MessagesApp', []);
app.controller('MessagesController', function($scope) {
  $scope.messages = ["a", "b"];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="MessagesApp" ng-controller="MessagesController">
  <div class="personWrapper" ng-repeat="message in messages">
    <p>{{message}}</p>
  </div>
</div>

Sign up to request clarification or add additional context in comments.

Comments

0

JS Code looks like below:

var app = angular.module('modelapp', []);
app.controller('ctrl', function($scope) {
      $scope.emplist = ["john", "marry", "jaison"];
});

HTML Code:

<div ng-app="modelapp" ng-controller="ctrl">
    <div ng-repeat="data in emplist">
         <p>{{data}}</p>
    </div>
</div>

It will load entire list, You can add class for div as per design, Even you can track index number also by using $index directive.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.