0

I am looking for a way to insert items inside elements in angular js.

Ill try to show how it is.

<item1> </item1>

insert an item like this

<item1>
    <item2> </item2>
</item1>

It also should insert all the data you require (it means it must execute the template of item2 when initialize).

I want to insert items dynamically, while press a button a new element is inserted into item1. The new one will be of a different type type2 and should inherit all the propertys and attributes of it's kind (item3, item3.. and so on).

2
  • create a directive item1 which template is <item2></item2> Commented Jul 11, 2016 at 12:14
  • Angular would be extreme overkill for accomplishing this. Commented Jul 11, 2016 at 12:17

1 Answer 1

2

You can achieve this using ng-include.

<item data-ng-include="'partials/your-template.html'"></item>

And attach to his own controller if needed.

<item ng-controller="YourCtrl" data-ng-include="'partials/your-template.html'"></item>

You can also create a custom directive like floribon advice, use ng-repeat, ng-bind-html...

Update from your comment

Use ng-show in this case

<item ng-show="isClicked">{{data}}</item>
<button ng-click="isClicked = true">insert</button>

That's the basics of angular use, you must read the bible before become a priest.

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

1 Comment

but the idea is to update, insert dynamically while you press a button, I have changed the description in order to explain it better, thanks anyway

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.