我已經在那裏我用NG-重複,讓我回我需要更改HTML類屬性對於每個NG-repeat元素與按鈕
<div>
<div class="col-sm-3" ng-repeat="el in vm.filmovi " id="filmovi">
<img src="http://image.tmdb.org/t/p/w500/{{el.poster_path}}" style="width:100%;"><br>
<a ng-click="vm.set_favorit(el)" style="cursor:hand; color:white;" uib-tooltip="Postavi u omiljene">
<i class="glyphicon" ng-class="{'glyphicon-star-empty':el.favorit!=true, 'glyphicon-star':el.favorit==true}"
aria-hidden="true"></i></a>
<a href="http://www.imdb.com/title/{{el.imdb_id}}/" style="color:white;">
<strong>{{ el.title | limitTo: 20 }}{{el.title.length > 20 ? '...' : ''}}</strong></a>
<a class="glyphicon glyphicon-share-alt" style="margin-left:5px; color:white;" ng-click="vm.open()" uib-tooltip="share" ></a><br>
{{el.popularity}} <br>
<a style="color:white;" href="#" ng-click="vm.filter(genre)" ng-repeat="genre in el.genres"><small>{{genre.name}} </small></a>
<div ng-init="x = 0">
<span uib-rating ng-model="x" max="5"
state-on="'glyphicon-star'"
state-off="'glyphicon-star-empty'"></span></div>
</div>
</div>
現在我創建了一個按鈕,改變的值從數組元素HTML DIV ID 「filmovi」
<li><a href="#" ng-hide="vm.ulogovan" ng-click="vm.dugme();" >losta</a></li>
和創建的函數vm.dugme(),通過ID獲取元件並設置類屬性附加傷害到COL-SM-4
vm.dugme=function(){
document.getElementById("filmovi").setAttribute("class","col-sm-4");
};
的3210
但是當我這樣做,只是第一個元素改變
,但我需要爲所有這些改變對col-SM-4,什麼建議嗎?
雖然瀏覽器會容忍重複的「id」值,但它是非法的HTML。這就像有一本書有重複的頁碼,這是一個非常糟糕的做法。 – georgeawg
在AngularJS中,DOM操作只能通過指令完成。在這種情況下,使用[ng-class指令](https://docs.angularjs.org/api/ng/directive/ngClass)來製作DOM類。 – georgeawg