AngularJS:使用指令添加HTML [英] AngularJS: Prepend HTML using Directive
本文介绍了AngularJS:使用指令添加HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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>
我尝试使用 jQlite 中提到的prepend
方法,但它不起作用.
I tried using prepend
method as mentioned in jQlite, but its not working.
- 如何在div
header00
之前显示指令? .append与 指令,但不.prepend在匹配的div之前添加任何html内容 元素. - 再次调用指令时,如何删除现有的html.
remove()
对我不起作用.
- 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.
推荐答案
您的代码只需进行简单的更改.将不存在的之前功能切换为 prepend (您说过已经尝试过,但是我确定这是解决此问题的方法).
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 ).
myEl.prepend($compile("<wave-spinner id='spinner00' ng-show='true'></wave-spinner>")($rootScope));
请确保我签入了jsFiddle- https://jsfiddle.net/maciejsikora/u5vLvxmx/
To be sure I checked in jsFiddle - https://jsfiddle.net/maciejsikora/u5vLvxmx/
这篇关于AngularJS:使用指令添加HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文