簡體   English   中英

AngularJS:如何對HTML5數據屬性使用ng-bind / ng-bind-template

[英]AngularJS: How to use ng-bind/ng-bind-template for HTML5 Data attribute

在我的代碼中,我有一個按鈕,並且通過使用HTML5數據屬性和AngularJs表達式向其顯示通知來將數據附加到它。 代碼是這樣的

<button type="button" 
        class="btn btn-link navbar-btn" 
        data-notifications={{tweetCount}}> 
    <span class="twitter-edit" ></span>
</button>

但是使用表達式的壞處可以在這里找到。 因此,顯然解決方案是使用ng-bindng-bind-template

但是如何對HTML5的data屬性執行此操作,因為在我的CSS中,我聲明了用於data-notification樣式,

[data-notifications]:after {
content: attr(data-notifications);
position: absolute;

top:1.75em;
right: -0.5em;
.
.
.
}

歡迎對此問題提出任何建議。

我對我的問題有些誤解。 上面顯示{{tweetCount}}代碼對我{{tweetCount}} 唯一的問題是,頁面加載時實際上會double curlies向用戶顯示double curlies 為了解決這個問題,建議使用ng-bind/ng-bind-template 但就我而言,我必須將其應用於HTML5的數據屬性標簽。 以及如何做?

我認為您只是錯過了車把周圍的引號。

<button type="button" 
    class="btn btn-link navbar-btn" 
    data-notifications="{{tweetCount}}"> <---quotes around the handle-bars
  <span class="twitter-edit" ></span>
</button>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM