Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
147 views
in Technique[技术] by (71.8m points)

AngularJs ng-Repeat Filter stop working on search with "!"

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...