0

How do I create a div element dynamically in AngularJS?

Example :

<table ng-controller="tableController">
 <tr ng-repeat="totaldivs in parameters">
    <td ng-repeat="divId in totaldivs">
    <!-- 
    want to replace something like below div
    <div id="days_01"><span>DIV_01</span></div>
     -->
    </td>
 </tr>
</table>

In jQuery we can do it using $('#IdOr.Class').html(param); How to do it using AngularJs ?

3
  • why can't you just put it there <td ng-repeat="divId in totaldivs"><div id="days_01"><span>DIV_01</span></div></div>? Commented Nov 18, 2016 at 18:05
  • I need to look at the url parameter something like index.php/?items=10&name='abc'&adr='address' then I need to append 10 rows with relevant parameters with new div /span etc Commented Nov 18, 2016 at 18:12
  • you don't usually create DOM elements manually, the framework does it for based on the template you specified. So just put correct information in the template Commented Nov 18, 2016 at 18:23

1 Answer 1

2

You're probably looking for something like this:

<table ng-controller="tableController">
 <tr ng-repeat="totaldivs in parameters">
    <td ng-repeat="divId in totaldivs">
       <div id="{{divId}}"><span>{{divContent}}</span></div>
    </td>
 </tr>
</table>

You're already inside a repeat loop, so the div will be created for each td. You just need to bind values to the divs.

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

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.