1
我想突出顯示正在創建表格的ng-repeat下的搜索文本。 我找到了一個過濾器作爲我的解決方案,但它不適用於表格。在表格數據中使用AngularJS過濾器+ ng-repeat突出顯示網格中的文本
任何人都可以指出我錯在哪裏使其工作。
<body ng-app="Demo">
<h1>Hello Plunker!</h1>
<div class="container" ng-controller="Demo">
<input type="text" placeholder="Search" ng-model="search">
<table>
<thead>
<th>Some</th>
<th>MyName</th>
</thead>
<tbody>
<tr ng-repeat="item in data | filter:search"
>
<td>
<td>{{item.title}}</td>
<td>{{item.name}}</td>
</td>
</tr>
</tbody>
<!-- with filter -->
</table>
</div>
<script>
angular.module('Demo', [])
.controller('Demo', function($scope) {
$scope.data = [
{ title: "Bad",name:'kaushik' },
{ title: "Good",name:'1kaushik' },
{ title: "Great",name:'2kaushik' },
{ title: "Cool" ,name:'3kaushik'},
{ title: "Excellent",name:'4kaushik' },
{ title: "Awesome",name:'5kaushik' },
{ title: "Horrible",name:'6kaushik' },
]
})
.filter('highlight', function($sce) {
return function(text, phrase) {
if (phrase) text = text.replace(new RegExp('('+phrase+')', 'gi'),
'<span class="highlighted">$1</span>')
return $sce.trustAsHtml(text)
}
})
</script>
</body>
This is working copy of the & demo the same thing I wants is with table.
沒有運氣與此 –
我只是增加了一個工作片段。具體來說,你是不是可以在你的代碼中工作? – Lex
thx mate,相同的代碼不適用於闖入者 –