2014-12-04 11 views
0

想象一下,我有一個包含多個HTML諧音,像這樣的字符串:註冊從單一的​​HTML *串多個諧音*

<script type="text/ng-template" id="ratings/down"> 
    <i class="fa fa-thumbs-o-down" 
     style="position: absolute; color: red; font-size: 2em; left: .6em; top: .3em;"></i> 
</script> 

<script type="text/ng-template" id="ratings/up"> 
    <i class="fa fa-thumbs-o-up" 
     style="position: absolute; color: #77AA33; font-size: 2em; left: .6em; top: .3em;"></i> 
</script> 

注意,這不是當前DOM的一部分。它在一個字符串變量中。我可以很容易地通過the $templateCache service註冊所有分支,並且不需要自定義字符串操作嗎?想象一下,HTML字符串更復雜一些,完全放棄了字符串操作的想法。我希望有一個更簡單的方法來做到這一點?我得到我不會讓周圍$compile擺弄的感覺...

+0

您可以通過將字符串解析爲HTML,然後迭代DOM中的'