【发布时间】:2015-09-10 12:11:44
【问题描述】:
是否有任何选项显示不同的glyphicon 图标取决于项目标题,问题是JSON 菜单列表可能变化
演示http://codepen.io/anon/pen/doZZgp
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope){
$scope.menuList = [
{page: "dashboard", title: "Dashboard"},
{page: "ui", title: "UI"},
{page: "expense", title: "Expenses"},
{page: "invoice", title: "Invoice"},
{page: "recur", title: "Reccurring Bills"},
{page: "profile", title: "My Profile"},
{page: "settings", title: "Settings"},
{page: "login", title: "Login"},
{page: "phonebook", title: "Phone book"}
]
});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app='myApp' ng-controller="myCtrl">
<ul class="nav">
<li ng-repeat="menu in menuList"><a href="#{{menu.page}}"><span class="glyphicon glyphicon-book"></span> {{menu.title}}</a>
</li>
</ul>
</div>
【问题讨论】:
-
您可以简单地
span class="glyphicon glyphicon-{{menu.page}}"。或使用ng-class。 -
当然可以。使用 ng 类。您只需要为每个菜单项关联一个图标。
标签: angularjs twitter-bootstrap-3 angularjs-ng-repeat ng-repeat glyphicons