AngularJs ng-Repeat Filter stop working on search with “!”

柔情痞子 提交于 2019-12-13 08:03:46

问题


AngularJS Filter of ng_repeat Doesn't work while searching with text "!". like searching text is "!icon". then it return result that don't contain "icon". i have also tried on angularjs.org.

https://docs.angularjs.org/api/ng/directive/ngRepeat

when i search "28" then it populates only two results but when i search "!28" then it return 8 result that dont contain 28.

Is there any way to considered "!" as a normal character.


回答1:


The filter in ng-repeat behaves exactly as specified in filter

The string is used for matching against the contents of the array. All strings or objects with string properties in array that match this string will be returned. This also applies to nested object properties. The predicate can be negated by prefixing the string with !

You can find the angular comparison code here. I believe there is no simple workaround - it's not a regexp, the code only checks whether ! is the first character. Even a custom comparator won't work cause the ! will still do a negation.

The easiest workaround is to create your own $filter for filtering and stop using the filter filter.



来源:https://stackoverflow.com/questions/29048673/angularjs-ng-repeat-filter-stop-working-on-search-with

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!