Answer the question
In order to leave comments, you need to log in
How to call the express function passed to pug?
I want to pass a function to the template (it should work on the server, not in the browser) and bind it to onclick on the button, but it doesn't work...
function startFn() {
console.log('test')
}
function (app, opts) {
app.get('/', (req, res) => {
res.render('index', {name: 'test', startFn: startFn})
})
doctype html
html
head
title= name
link(rel="icon" type="image/png" href="/public/favicon.png")
body
button(type="button" alt=name onclick=startFn ) Start fn
<!DOCTYPE html>
<html>
<head>
<title>test</title>
<link rel="icon" type="image/png" href="/public/favicon.png">
</head>
<body><button type="button" alt="test" onclick="undefined">Start fn</button></body>
</html>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question