Creating multiple divs or objects dynamically from front end

26 views
Skip to first unread message

ng-user

unread,
Jun 26, 2014, 4:51:23 PM6/26/14
to ang...@googlegroups.com
Hi,

I'm trying to make a task management site and I want to create a feature where users can click on a button and that will create a new div for them or a new object for them which they can edit by adding a title and description. And they can create as many as they want.

Can anyone help me to understand how I can do this as I am new to angular I can't figure it out.

I thought about creating an object and using a append.child function to create editable objects dynamically.

Can anyone please help??

Thanks in advance.

Eric Eslinger

unread,
Jun 27, 2014, 10:35:42 AM6/27/14
to ang...@googlegroups.com
Generally speaking, that's the wrong way to do it.

Check out TodoMVC, the Angular version for some specifics. But the idea is, you have an array of to-do items stored as a plain old javascript object. Pressing the button calls todos.push(new item). Add some other controls for editing or deleting objects from the array. Then you do an <div ng-repeat="todo in todos">, and you'll get one div per todo item, free and clear. Don't muck around with appendchild or any other direct DOM manipulation. You provide the data model, angular makes sure that the dom reflects that data model.

e



--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages