yoyo burger yoyo burger - 3 months ago 15
AngularJS Question

AngularJS escaping quotes

I am having a hard time escaping quotes in from the following statement

on-mouseover="mouseover('{{landmark.name}}')"

where
landmark.name="Duke's Car"


I tried various solutions like:

$scope.escapeQuotes= function(str) {
return str
.replace(/('|\")/g, "\\$1")
.replace(/("|\")/g, "\\$1")
}


But it does not seem to work. Looks like a simple problem but I am having a hard time finding a solution. Any pointers are welcome.

Answer

I'd say use ng-mouseover instead, you don't need to worry about that escaping things

ng-mouseover="mouseover(landmark.name)"

Code

$scope.mouseover = function(name){
   console.log("Value output:", name)
}