Tuesday, 15 September 2015

javascript - Cannot set property 'round' of undefined in ejs -


I am learning nodes from the "hide of ninja" book. I have an EJS program that I copied to run from the book, but it is showing the following error unless I make any changes to the program.

This is an error:

  Ejs.filters.round = function (number, decimal place) {^ Can not set property 'round' undefined  

I have this code:

  var Ejs = require ('ejs'); Var template = '& lt;% =: value * 1.145 | Round: 2% & gt; '; Var reference = {value: 21}; Ejs.filters.round = function (number, decimal place) {number = isNa (number)? 0: Number; Decimal places =! Decimal place? 0: decimal places; Var multiple = Math.pow (10, decimal place); Return math grounds (number * multiple) / multiple; }; Console.log (ejs.render (template, context));  

Does anyone tell me where I am wrong?

Maybe you're using version 2.

EJS version 2 makes some changes with this version (in particular, delete the filter feature) )


Edit:

You can either switch to a version before version 2, or create your own object for the filter, Which can then be extended to include its own defined filter


No comments:

Post a Comment