Я боролся некоторое время за помощью.Это действительно странно.Я хочу получить доступ к свойству объекта, но это всегда выдает ошибку:
TypeError: невозможно прочитать шаблон свойства undefined
Но мое приложение работает правильно.Просто есть уведомление, если нет доступа к шаблону undefined
//this is my object variabel
var login = {};
login.data = {
checkInput : formValidation,
userSchema : User,
template : 'pages/users/login',
}
// so I add new method which I call in different files
login.header = async(req, res, next) => {
/// in this section function I want to read property of template but it always return undefined
try {
// I have some code with read databases here
//some data i want to render
var data = {};
res.render(this.data.template,data);
// I've been also trying another way.
var template = login.data.template !== undefined ? 'page/users/login' : login.data.template;
res.render(login.data.template, data);
// both of above always return output, but can't read template of undefined
} catch(e) {
throw new Error(e);
}
}