admin管理员组文章数量:1025278
I try to use string match with ignore case sensitivity and my input $scope.search
variable, but it doesn't work.
<input type="text" ng-model="search" autofocus="autofocus">
angular.forEach(groups, function(group, key) {
console.log(group); // => Object contains
if (group.label.match(/($scope.search)/i)) {
result[key] = group;
}
});
Data Object group:
Object { label: "Transfiguration", articles: Array[1] }
How to use group.lable.match() with $scope.search
correctly?
Many thanks.
I try to use string match with ignore case sensitivity and my input $scope.search
variable, but it doesn't work.
<input type="text" ng-model="search" autofocus="autofocus">
angular.forEach(groups, function(group, key) {
console.log(group); // => Object contains
if (group.label.match(/($scope.search)/i)) {
result[key] = group;
}
});
Data Object group:
Object { label: "Transfiguration", articles: Array[1] }
How to use group.lable.match() with $scope.search
correctly?
Many thanks.
Share Improve this question edited Jan 5, 2015 at 14:05 asked Jan 5, 2015 at 13:52 user4420255user44202552 Answers
Reset to default 1Your regular expression is dynamic so you cannot use /regexp/
syntax. You need to create a Regexp
object instead.
angular.forEach(groups, function(group, key) {
console.log(group); // => Object contains
if (group.label.match(new RegExp("(" + $scope.search + ")", "i"))) {
result[key] = group;
}
});
You can probably remove the brackets from the RegExp too.
It is better also to use test()
because you aren't interested in the results:
if(new RegExp($scope.search, "i").test(group.label)) {
Finally, if this is a basic search, putting both parts to lower case and using indexOf
should be more efficient:
if (group.label.toLowerCase().indexOf($scope.search.toLowerCase()) > -1) {
you can always use javascript in angularjs modules :)
angular.forEach(groups, function(group, key) {
console.log(group); // => Object contains
if (group.label.toLowerCase().indexOf($scope.search.toLowerCase())!=-1) {
result[key] = group;
}
});
This should solve your problem
I try to use string match with ignore case sensitivity and my input $scope.search
variable, but it doesn't work.
<input type="text" ng-model="search" autofocus="autofocus">
angular.forEach(groups, function(group, key) {
console.log(group); // => Object contains
if (group.label.match(/($scope.search)/i)) {
result[key] = group;
}
});
Data Object group:
Object { label: "Transfiguration", articles: Array[1] }
How to use group.lable.match() with $scope.search
correctly?
Many thanks.
I try to use string match with ignore case sensitivity and my input $scope.search
variable, but it doesn't work.
<input type="text" ng-model="search" autofocus="autofocus">
angular.forEach(groups, function(group, key) {
console.log(group); // => Object contains
if (group.label.match(/($scope.search)/i)) {
result[key] = group;
}
});
Data Object group:
Object { label: "Transfiguration", articles: Array[1] }
How to use group.lable.match() with $scope.search
correctly?
Many thanks.
Share Improve this question edited Jan 5, 2015 at 14:05 asked Jan 5, 2015 at 13:52 user4420255user44202552 Answers
Reset to default 1Your regular expression is dynamic so you cannot use /regexp/
syntax. You need to create a Regexp
object instead.
angular.forEach(groups, function(group, key) {
console.log(group); // => Object contains
if (group.label.match(new RegExp("(" + $scope.search + ")", "i"))) {
result[key] = group;
}
});
You can probably remove the brackets from the RegExp too.
It is better also to use test()
because you aren't interested in the results:
if(new RegExp($scope.search, "i").test(group.label)) {
Finally, if this is a basic search, putting both parts to lower case and using indexOf
should be more efficient:
if (group.label.toLowerCase().indexOf($scope.search.toLowerCase()) > -1) {
you can always use javascript in angularjs modules :)
angular.forEach(groups, function(group, key) {
console.log(group); // => Object contains
if (group.label.toLowerCase().indexOf($scope.search.toLowerCase())!=-1) {
result[key] = group;
}
});
This should solve your problem
本文标签: javascriptHow to use string match() with angularJs scopesearch variableStack Overflow
版权声明:本文标题:javascript - How to use string match() with angularJs $scope.search variable - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745614685a2159215.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论