'Angularjs how to do IF CONTAINS in $scope?
I want to know if it's possible to know if there are a char in a $scope for example something like this but in angularJs
$scope.test = "Hi, How Are You?";
if($scope.test.Contains("?")) {
return true
} else {
return false
}
Solution 1:[1]
You can just replace Contains
with match
:
if($scope.test.match("?")) {
return true
} else {
return false
}
And you can even further optimize this whole code block to just:
return !!$scope.test.match("?");
Solution 2:[2]
Well you can do it like this..
var string = "hello";
alert(string.indexOf("llo") != -1);
so in regards to your code above..
$scope.test= "HI How Are You ?";
alert($scope.test.indexOf("How") != -1); // return true;
Solution 3:[3]
Try the codes below:
ng-attr-target="{{(p.link.indexOf('https://')!=-1) ? '_blank' : _self}}"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Shomz |
Solution 2 | ryeballar |
Solution 3 | Suraj Rao |