使用angularjs
我有3个选择下拉列表和一个获取json列表的按钮
焦点选择下拉列表如下所示:
<select id='sort' ng-model='sort'>
<option value='1'>ID</option>
<option value='2'>Departmentname</option>
<option value='3'>Number of employees</option>
</select>
<button ng-click="getinfo()">GET INFO</button>
表格如下所示
<table>
<tr> <td>{{ depid }}</td> <td>{{ depname }}</span></td> <td>{{ depemp }}</td></tr>
在控制器中我有:
$scope.depid = "Department id";
$scope.depname = "Departmentname";
$scope.depemp = "Number of employees";
$scope.getinfo = function() {
var url = "";
...
}
基于选择&#34;排序&#34;我希望sort列为粗体/强或大写。
我该怎么做?
答案 0 :(得分:2)
您可以在td
元素上使用ng-class:
<tr>
<td ng-class="{bold : sort == 1}">{{ depid }}</td>
<td ng-class="{bold : sort == 2}">{{ depname }}</span></td>
<td ng-class="{bold : sort == 3}">{{ depemp }}</td>
</tr>
添加CSS规则:
.bold {
font-weight: bold;
}
这是Fiddle演示。
答案 1 :(得分:0)
跟随Omri Aharon我改变了
ng-class =&#34; {bold:sort == 1}&#34;
至
ng-class =&#34; {bold:sortby == 1}&#34;
并遵循Nayish我把内部跟随控制器
$ scope.getinfo = function(){
var url =&#34;&#34;;
...
$ http.get(URL)
.success(function(response){
$ scope.names = response;
$ scope.sortby = $ scope.sort;});
}
非常感谢你们两个人!