Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I've a HTML line with AngularJS directive that I am inserting dynamically through some jQuery controls that are being used since 2009. I cannot change this Control. However, I want to start using angular JS.

The generated HTML for a grid, column rating, is:

  <div star-rating rating-value="1005" max="5"> </div>

What I want is to get this html compiled.

At present AngularJS is not able to see this dynamically generated HTML.

The only way I can think of is if I call a javascript function for each jQuery insert (The Grid control I am using can compile JavaScript function).

fnCompileDynamicHTML('<div star-rating rating-value=23 max=5></div>)

And function:

fnCompileDynamicHTML(html) {
    return $compile(html)($scope) // or something?
}

I have followed what is mentioned here. However my application is complaining about:

App Already Bootstrapped with this Element.

Well it is not because it is a new object, and new inner HTML.

This is what I have in the loop of 100:

 evt.row.cells[glbCandidateListColumnIndex.rank].innerHTML = '<div star-rating rating-value="' + rank + '" ></div>';
 fnCompileDynamicAngularJS(evt.row.cells[glbCandidateListColumnIndex.rank]);

Please help.

share|improve this question
    
Anyone, please!? –  codebased Feb 13 '14 at 1:02
    
Anyone, please? –  codebased Feb 13 '14 at 3:48
    
evt.row.cells[glbCandidateListColumnIndix.rank].appendChild(fnCompileDynamicAng‌​ularJS('<div star-rating rating-value="' + rank + '" ></div>')); ? A call to $compile(html)(scope) returns an $element which you have to append to the right place. You may also need a call to .node() on the returned $element to get the DOM element. –  musically_ut Feb 15 '14 at 0:14

1 Answer 1

You should either load Angular.js after the DOM compilation by your foreign library is done, calling angular.bootstrap (documented here), or you can force the compilation of that particular DOM node manually (harder!!!)

As an example:

angular.module('myApp', []).directive('myDirective', function () {});
angular.bootstrap(document.body, ['myApp']);

That should work already!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.