現在、この配列と一致するものがあれば、リスト内の単語をハイライトするコードがあります。angularjsの範囲のテキストを強調表示
$scope.arrayFilter=["is","mom","beautifull",'beer'];
このコードはもう必要ありません。私は "マーキー"効果を行うライブラリの効果を失うことなく、配列からクラス ".marque"のテキストをハイライトする必要があります。どうすればいい?
https://jsfiddle.net/mafa4hro/
<div ng-app="testApp" ng-controller="testCtrl">
<li ng-repeat="item in data ">
<span ng-bind-html="item.title | highlight:arrayFilter"></span>
</li>
<div class='marquee' >mom is beautifull</div>
</div>
var app = angular.module('testApp',[]);
app.controller('testCtrl',function($scope){
$scope.arrayFilter=["mom","is","beautifull",'beer'];
$scope.data = [{
title: "mom is beautifull"
}, {
title: "my mom is great"
}, {
title: "I hate the matematics"
}];
//marquee effect
$('.marquee').marquee({
duration: 5000
});
$('.marquee')
.bind('finished', function(){
console.log('finish')
$(this).html('If it works, i need a beer')
//Apply marquee plugin again
.marquee({
duration: 5000,
})
})
});
app.filter('highlight', function($sce) {
return function(text, arrayFilter) {
angular.forEach(arrayFilter, function(key, value) {
if (text.includes(key)) {
text = text.replace(new RegExp(key, 'gi'), '<spanclass="highlightedText">$&</span>')
}
})
return $sce.trustAsHtml(text);
}
});
あなたは自分の車種のテキストに色をしたい場合、あなたは '色持つことができます。あなたの内部の「color_name''を'.marquee' –
@AkashKCそして、マッチした配列の言葉をどのようにハイライトしますか? – yavg
@yavgクラス 'marquee'を持つ要素が配列の外にあるので、フィルタは適用されません...質問を詳しく述べてください。 – kukkuz