我是 AngularJS 的新手,想知道如何将我在页面中搜索的语句加粗。我正在使用过滤器方法来过滤表,但我也想将过滤后的语句加粗。例如,如果我正在搜索
test
我希望将以下内容加粗:
this is a <b>test</b>
etc
这是我的 Controller 代码:
function PhoneListCtrl($scope, $http) {
$http.get('/text.json').success(function(data){
$scope.phones = data;
});
$scope.hello = "Hello, World";
$scope.orderProp = 'age';
$scope.query = "";
//$scope.query
$scope.smart_filter = function(item){
item = item.snippet;
var query_words = $scope.query.split(" ");
return query_words.every(function(word){return item.indexOf(word) != -1})
};
$scope.test = function(item){
return "<b>" + item + "</b>";
}
最佳答案
看一下 Angular UI-Utils 的高亮模块。它正是您想要的。
关于javascript - AngularJS 搜索框中的粗体语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18550336/