Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

How to add object in array and show it on web-page?

http://plnkr.co/edit/19w1Q3XhoWQcpxm5SuxX?p=preview

$scope.add = function() {
$scope.items.push($scope.item);
$scope.item = '';

};

When I try to add item it's not show on page

share|improve this question
1  
Just change the first line of you dd function to $scope.items.push({'item':$scope.item}); so the item object will have the same structure of data than the others. – Walfrat Jun 27 at 9:28

Hi just edit your function

because its an object , u have to create object and need to push inside an array

$scope.add = function() {
    var obj ={};
    obj.item = $scope.item;
    $scope.items.push(obj);
    $scope.item = '';
  };
share|improve this answer

Just change your push code to:

$scope.items.push({item: $scope.item});

You are trying to push single string to an Array of objects.

you can also change your model in controller to

$scope.item = {text: ""}

and on your view change ng-model to

ng-model="item.text"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.