mde / ejs

Embedded JavaScript templates -- http://ejs.co
Apache License 2.0
7.71k stars 846 forks source link

arrow function getting interpreted as closing tag #618

Closed Ankur-Khandelwal closed 2 years ago

Ankur-Khandelwal commented 3 years ago

I want to use an arrow function inside an ejs scriplet tag as shown below: <button type="button" class="loveButton" id="<%= post._id %>" onclick=<% () => loveFunc(event) %> > However the arrowhead is being interpreted as the closing tag for the ejs tag there.

jkalandarov commented 3 years ago

If you already declared loveFunc function, why do you still want to use anonymous function? You can simply use onclick=<% loveFunc(event) %>

Ankur-Khandelwal commented 3 years ago

@jkalandarov because without using the anonymous function, the function is getting called even without clicking the button.

Kalud-Z commented 2 years ago

@Ankur-Khandelwal did you figure out how to do this ? Im stuck also

Ankur-Khandelwal commented 2 years ago

@Kalud-Z No, I couldn't.

RyanZim commented 2 years ago

You're confusing templating and HTML event attributes. You can't call a function in your EJS onclick.