To create a new empty list by clicking on "new list"

Asked

Viewed 111 times

0

Good afternoon,

I have an array of objects and display them in a list, in the list there is an input to insert new objects. I want to make a button where I would create a new zeroed list with the same input to insert new objects. How would you have the lists display only the objects that were inserted into it?

I’m doing with Angularjs and I’m not able to create this new list, it pulls the other objects too.

Does anyone have any tips for me to implement this list?

1 answer

1


If I understand your problem, unintentionally, you bumped into one of the most interesting features of Angularjs: A capacidade de manter um escopo bindado mesmo quando você muda ele de lugar.

The quick answer is: Use angular.copy() to copy your list to a new place, so Angularjs creates a new item in its scope without linking your copy to the previous scope.

If you’re interested in seeing an example of how to use angular.copy() in an application similar to the one you’re mounting, see this plnkr q I rode. I put several comments in the code to help understand the logic.

I used this pattern of projects to assemble the code of this example. The pattern in question was developed by a guy named John Papa and is maintained by a gigantic community, which includes Google professionals.

  • Thank you, very good this example, was just what I needed.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.