简体   繁体   中英

javascript variable comparison behaviour

I am facing very strange issue while I am trying to compare two string with the help of regex. also I tried to compare both variable in watch, but unfortunately I am getting same result. Please help me to find the cause. My code is below and I am attaching an image where I have compared two variable values. In below code, for ex: if text="Acworth, GA" and search="Acworth, GA" or search="acworth, ga" then final_str does not have <span class="highlight" .

I'll really appreciate if you have any suggestion.

app.filter('highlight', function($filter, $sce) {
  return function(text, search, caseSensitive) {
    if (search == undefined)
      search = searchDataBrowser;

    text = text.toString();
    search = search.toString();

    var reg = new RegExp(search, 'gi');

    var final_str = text.replace(reg, function(str) {
      return '<span class="highlight">' + str + '</span>'
    });

    return $sce.trustAsHtml(final_str);
  };
});

在此处输入图片说明

I found the cause of my problem. Thanks guys for your valuable time. Problem was in first string value, while rendering the input it contains for space. That is why you can check on attached image , the same values do not match each other. I simply remove the &nbsp from binding, and it works for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM