0

I'm new to AngularJS and am wondering how to bold statements that I'm searching for in the page. I'm using the filter method to filter a table, but I'd like to bold the filtered statements as well. For example, if I'm searching for

test

I'd like the following to be bolded:

this is a <b>test</b>
etc

Here's my controller code:

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>";
  }
4

2 回答 2

1

如果我理解正确,您想“不安全地绑定”您的文本:

<span ng-html-bind-unsafe="textWithMarkup"></span>
于 2013-09-01T01:07:54.450 回答
1

看看Angular UI-Utils的 Highlight 模块。它正是你想要的。

于 2013-08-31T17:31:43.970 回答