0
id name = search-query 인 변수에 입력 텍스트 값을 저장했습니다. 그런 다음 JSON 데이터를 검색하여 일치하는 결과를 찾은 다음 결과를 화면에 출력합니다. search-query.val과 일치하는 단어를 대담하게 표현할 수있는 방법이 있습니까? 대신 ng-bind-html을 사용하려고했지만 결과를 출력하지 않습니다. 검색어와 일치하는 단어를 정규식과 각도로 변환
<body ng-app="products" ng-controller="ctrl">
<input type="text" id="search-query" name="query" placeholder="Enter product name"></input>
<tbody>
<tr ng-repeat="result in searchResult|orderBy:order:reverse" >
<td >
<a ng-href="{{result.link}}" target="_blank">
//used ng-bind-html or ng-bind, but does not works
<span ng-bind-html="result.name" target="_blank"></span>
</a>
</td>
<td ng-bind="result.type"></td>
</tr>
</tbody>
var app2 = angular.module('products', []);
app2.controller('ctrl', function($scope) {
$scope.searchResult = [];
$scope.submit = function(){
var search = $("#search-query").val();
$.each(json.products, function(i, v) {
var regex = new RegExp(search, "i");
if (v.name.search(regex) != -1) {
// For the following line, is there a way which I can bold the word which match the search-query.val?
var name = v.name.replace(search, "<b>search</b>"); // doesn't work
$scope.searchResult.push({ name:name, type: v.type, link: v.url });
return;
}
});
}
<스팬 대상 = "_ 빈"> {{result.name}}'. 'ng-bind-html'은 html 문자열을 span 요소에 바인드합니다. –
감사하지만 작동하지 않습니다. 형식 태그를 html의 텍스트로 출력합니다. 경험 : "Neuberger Berm a n" – user21