Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs Angular.js文本按搜索关键字高亮显示需要建议_Angularjs - Fatal编程技术网

Angularjs Angular.js文本按搜索关键字高亮显示需要建议

Angularjs Angular.js文本按搜索关键字高亮显示需要建议,angularjs,Angularjs,我正在尝试使用搜索关键字突出显示文本。我尽力了。但我无法得到我所需要的结果 现在我不知道如何进一步完成我的要求。是否有人给出正确的建议或帮助我完成通过搜索关键字突出显示的功能 实际上,我的search输入位于页面的标题中。(全局)我想通过关键字条目突出显示页面中的文本 这是我的密码: var app = angular.module('plunker', []); app.controller('headerController', function ($scope) { var rep

我正在尝试使用搜索关键字突出显示文本。我尽力了。但我无法得到我所需要的结果

现在我不知道如何进一步完成我的要求。是否有人给出正确的建议或帮助我完成通过搜索关键字突出显示的
功能

实际上,我的
search
输入位于页面的标题中。(全局)我想通过关键字条目突出显示页面中的文本

这是我的密码:

var app = angular.module('plunker', []);

app.controller('headerController', function ($scope) {

  var replacer = function(match, item) {
            return '<span class="highlight">'+match+'</span>';
    }

  var tokenize = function(keywords) {
            keywords = keywords.replace(new RegExp(',$','g'), '').split(',');
            var i;
            var l = keywords.length;
            for (i=0;i<l;i++) {
                keywords[i] = '\\W'+keywords[i].replace(new RegExp('^ | $','g'), '')+'\\W';
            }
            return keywords;
        }

  $scope.search = {value:''}

  $scope.$watch('search.value', function(newval, oldval) {

    if(!newval) {
      return false;
    }

    var tokenized   = tokenize(newval); 
    var regex       = new RegExp(tokenized.join('|'), 'gmi');

   console.log( tokenized );

  })


})

app.controller('controller1', function($scope) {

  $scope.para1 = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.';

});

app.controller('controller2', function($scope) {

  $scope.para2 = 'It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.';

});

app.controller('controller3', function($scope) {

  $scope.para3 = 'The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.';

});
var-app=angular.module('plunker',[]);
应用程序控制器('headerController',功能($scope){
var replacer=功能(匹配,项目){
返回“”+匹配+“”;
}
var tokenize=函数(关键字){
关键字=关键字.replace(新的RegExp(',$,'g'),'').split(',');
var i;
var l=关键字。长度;

对于(i=0;iMaybe),这将帮助您我猜他们使用插件,而UI-我在这里不使用插件。您的plunker已更新。基本上,它使用的技术如下所述: