Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS and HTML: Escaping quotes inside a variable for an onclick function

i'm just wondering how to escape a function if it has quotes inside. for example, my variable is:

   {{ video.Id }} = "Don't";

then if my markup in html is like this:

    <button ng-click="executeFunc('{{video.Id}}')"/>

I will have an error saying that I have unterminated quotes. (Coming from the variable that have quotes inside.) Any help would be appreciated! thank you

like image 781
rnldpbln Avatar asked Dec 11 '13 16:12

rnldpbln


People also ask

How do you escape quotes in JavaScript?

Javascript uses '\' (backslash) in front as an escape character. To print quotes, using escape characters we have two options: For single quotes: \' (backslash followed by single quote) For double quotes: \” (backslash followed by double quotes)

How do I bypass a single quote in JavaScript?

We can use the backslash ( \ ) escape character to prevent JavaScript from interpreting a quote as the end of the string. The syntax of \' will always be a single quote, and the syntax of \" will always be a double quote, without any fear of breaking the string.


1 Answers

You don't need the inner {{}}, just do <button ng-click="executeFunc(video.Id)"/>

Your controller function, executeFunc will get the proper value.

like image 199
Jonathan Rowny Avatar answered Sep 19 '22 15:09

Jonathan Rowny