问题
I am having an issue with a script in express. I am calling a function that renders a view, on the success of another function. In this project I am utilizing angular, node, express, and ejs as view engine. When I render the view, I unfortunately receive an ejs error of the following:
ReferenceError: /Users/emilywfrancis/Desktop/nodejs-angularjs-sequelizejs/views/about.ejs:5
3| <html ng-app="app">
4| <meta charset="utf-8">
5| <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/3.1.0/css/font-awesome.min.css" />
6| <% include header %>
7| <% include navbar %>
8| <body>
title is not defined
Here is the code:
exports.verifyusers= function(req, res) {
models.user.find({
where: {
email: req.body.email,
password: req.body.password
}
}).then(function(res, user) {
if(user == "user.name") { //if user exists in database
res.render('/about')
};
});
};
回答1:
Seems like the error is actually in the header file which proprely contains something like:
<%= title %>
I think changing changing it to the following will work:
<%= (typeof title != "undefined" ? title : "") %>
回答2:
You need to give your title a value, if not already done. If it is done, then @andlrc answer is correct, but you still want to figure out why it is throwing an error. If not, it is bad practice.
In your server define a variable names title and give it a string. Then expose is to your view.
In this answer you find an example.
来源:https://stackoverflow.com/questions/37732986/ejs-js-referenceerror-title-not-defined