angular-expressions
angular-expressions copied to clipboard
Could not parse DOM element properties
In my case, I give a DOM element to scope, and want to parse out the value property, but not work:
const el = document.querySelector('#input')
const ev = expressions.compile('el.value')
console.log(ev({ el }))
I get undefined, could you please to fix this?
Hello @tangshuang , I don't have the time to put active work like this on the project because of other priorities. If you write a pull request, I will look at it.
@tangshuang your code is wrong, you need to use the value of the element for the expression, not the string "el.value". That is:
const el = document.querySelector('#input')
const evaluate = expressions.compile(el.value)
console.log(evaluate({}) // whatever scope you need
This assuming of course the expression is in the input.
EDIT: I understand now that what you want is to evaluate an expression using the element value. If it doesn't work it's probably because it's not enumerable (own property) or something similar. We've noticed many "standard things" do not work as expected inside the angular parser.
@cdelaorden you are right, I modified the code, see here https://github.com/tangshuang/scopex/blob/master/index.js (may face secure problem, not sure)