1

I'm trying to extract a raw HTML table of data from a table which I currently generate on a web page using AngularJS.

To give a simple example:

Angular code:

  <table>
    <tr ng-repeat="customer in customers">
        <td>{{customer.firstname}}</td>
        <td>{{customer.lastname}}</td>
    </tr>
  </table>

I don't want to code two different solutions and so would like to use AngularJS.

Is it possible to extract the raw html code using AngularJS? i.e. the following :

  <table>
    <tr>
        <td>John</td>
        <td>Smith</td>
    </tr>
    <tr>
        <td>Fred</td>
        <td>Bloggs</td>
    </tr>
    ...etc
  </table>
2
  • 2
    You should consider it render at server side then. Maybe this will help : stackoverflow.com/questions/16232631/… Commented Jun 17, 2015 at 15:49
  • I may go that route, so its a useful pointer. I would prefer to keep it client side if possible though. Commented Jun 18, 2015 at 8:24

1 Answer 1

2

you can use

  var element = angular.element(element)

   element[0] //show give raw dom element

refer jqlite and below link in angularJS , probably will get idea https://docs.angularjs.org/api/ng/function/angular.element

Fiddle: https://jsfiddle.net/shushanthp/Lho8myw2/

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

4 Comments

Interesting. Looks like this could do the job. If you have a working example I will accept it as the correct answer.
@JeffYates Glad to help :) , Its recommend and good approach to use directive for this , i have added the fiddle on the same , hope it helps
Perfect. Does the job. Very simple. Thanks @shushanth
@JeffYates :) :) . happy to help you jeff , no problem , :) ,

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.