我有一個<input />
標記,我想用一些特定的Div
標記換行。我正在制定自定義指令,在其中我要實現此功能。但是我面臨的問題是,element
的prepend()
方法增加了整個標籤,即它在目標input
標籤之前開始和結束。同樣,在element
append()
方法追加input
標籤內的Div
,而我真正想要的是,使用自定義指令的div換行html元素
在HTML:
<input id="oldinput" custom-textbox /> <!-- custom-textbox is my directive -->
應用指令,中源之後,我想這樣:
<div id="mynewdiv> <!-- added from directive -->
<input id="oldinput" custom-textbox /> <!-- present input tag where I'd apply my directive -->
<div id="othernewdiv" /> <!-- new div to be added from directive -->
</div> <!-- end of newly added div from directive -->
但使用後的結果append()
個prepend()
功能:
<div id="mynewdiv> </div> <!-- added from directive, div ends here only -->
<input id="oldinput" custom-textbox > <!-- present input tag where I'd apply my directive, doesn't end here -->
<div id="othernewdiv" /> <!-- new div to be added from directive, it's added inside input tag -->
</div> <!-- end of newly added div from directive -->
</input> <!-- Wraps my newly added div -->
完全陌生的行爲。有人可以幫我弄這個嗎?
謝謝,這個伎倆。但是現在這個新添加的元素沒有被編譯。我在這裏發佈了這個問題 - http://stackoverflow.com/questions/23051494/newly-added-elements-from-angular-directive-not-getting-compiled。爲什麼它沒有被編譯?我應該如何讓它工作,以便'div'顯示那裏的角度變化? –