Javascript variable inside the EJS tag

Asked

Viewed 295 times

0

How to place a javascript variable inside the EJS tag?

For example, I wish to make a for by EJS and a if comparing:

<% for (var i = 0 ; i < objeto.lenght; i++ ) { %>
    <% if (objeto[i].index == variável_externa) { %>
        ..... 
    <% } %> 
<% } %> 

''' My code is below: I want to put a javascript variable inside an EJS '''

document.getElementById("indicadores1").addEventListener('change', (event) => {
// Aqui eu obtenho meu value 
let indicador_atual = event.target.value;
console.log(indicador_atual);
// Agora preciso colocar esse valor dentro de uma váriavel EJS

Por exemplo :<% x %>= indicador_atual

2 answers

0

You can use <%= variavel %> or <%- variavel %>.

The difference between the two modes is that <%- variavel %> interprets HTML code, while <%= variavel %> nay.

Source

0

You can use <%= variavel %>, similar to PHP.

<% for (var i = 0 ; i < objeto.lenght; i++ ) { %>
    <% if (objeto[i].index == variável_externa) { %>
        <%= objeto[i].nome %>
    <% } %> 
<% } %> 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.