我正在尝试将用 html/jquery 编写的旧应用程序移植到 angularjs。场景是有一个列表,点击 chevron 它会在其下方显示一组图标(下图)
要走的路是指令性的,我试图修改一个以适应这种情况。我不清楚的是我将如何一次只限制一组图标。
在 Jquery 中它相当简单,所有图标集都有作为图标集的类,所以你做了 $(".icon-set").hide() 并且它会隐藏所有图标,并且在需要时,即点击 chevron 显示图标。
在角度的情况下,我有多个问题。我创建了这个列表
<ul class="list" ng-repeat="file in files| filter: { folder:'false' }" >
<li class="list-main" >
<ext-img file-name="{{file['file-name']}}"></ext-img>
<div class="list-info">
<div class="list-header">{{file['file-name']}}</div>
<div class="list-info-bottom dimfont"><small>{{ file['modified-timestamp'] | date:'medium' }}</small></div>
</div>
<action-button class="chevron" id="{{file['file-path']}}/{{file['file-name']}}"></action-button>
</li>
</ul>
该指令不适用于 element.bind() (下面的代码),我如何仅对列表元素之一显示它。
myapp.directive('action-button',function(){
return {
restrict: 'E',
template: {
},
link: function(scope,element,attrs){
// This populates the options mene, Bind onclick event
element.bind("click",function(){
// Append the options to it.
var str = '';
str += "<div class=\"options-box\">" ;
str += "<ul class=\"options-inner\">" ;
str += "<li class=\"options-item\">" ;
str += "<a href=\"#\" ng-click = \"\">" ;
str += "<img class=\"options-img\" src=\"images/share_file.png\">" ;
str += "<div>Share</div>" ;
str += "</a>" ;
str += "</li>" ;
str += "</ul></div>";
element.replaceWith(str);
}
)
}
}
})
编辑:我可以解决不工作的问题,我感到困惑的是如何让它只显示一个图标集。编辑:修正错字