Reputation: 944
I wrote a little program in angular containing a method which search for a string in a string array like that :
function searchStringInArray(str, strArray) {
for (var j = 0; j < strArray.length; j++) {
if (strArray[j].match(str)) return j;
}
return -1;
}
To optimize my code, I thought about using jquery because we can do that in just one line (just by using the minified version in angular) WITHOUT importing the jquery library (before the angular script).
So, I wanted to try this new code :
$scope.check = $.inArray($scope.message, $scope.messages) ;
But it didn't work at all, the console tells me that $ is not defined.
Here is a test code in plunker : https://plnkr.co/edit/ftNU3UM7UpKvgL0Jozdy?p=preview
Can you help me to fix that problem?
Thank you
Upvotes: 0
Views: 54
Reputation: 220
You can store the $ of jQuery in any variable for escape the conflict between two languages.
The noConflict() method releases the hold on the $ shortcut identifier, so that other scripts can use it.
For Example:-
var jq = $.noConflict(); jq(document).ready(function(){
jq("button").click(function(){
jq("p").text("jQuery is still working!");
});});
Upvotes: 1