Service.js
this.showSpinner = function (Id) {
angular.element("<wave-spinner id='spinner00' ng-show='true'></wave-spinner>").remove();
var myEl = angular.element(document.querySelector("#header00"))
myEl.prepend($compile("<wave-spinner id='spinner00' ng-show='true'></wave-spinner>")($rootScope));
};
HTML
<div id="header00" style="">Some Content</div>
I tried using prepend
method as mentioned in jQlite, but its not working.
- How do I show directive before div
header00
? .append works with directive but not .prepend to add any html content before matched div element. - When directive is called again, how do I remove existing html.
remove()
is not working for me.
Your code only needs a simple change. Switch the before function which does not exist to prepend ( You said that you have tried it but I'm sure this is the solution to this problem ).
To be sure I checked in jsFiddle - https://jsfiddle.net/maciejsikora/u5vLvxmx/
You can do it this way:
and in service.js