angular-expressions icon indicating copy to clipboard operation
angular-expressions copied to clipboard

Could not parse DOM element properties

Open tangshuang opened this issue 3 years ago • 3 comments

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?

tangshuang avatar Mar 05 '21 04:03 tangshuang

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.

edi9999 avatar Mar 05 '21 10:03 edi9999

@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 avatar Jun 08 '21 15:06 cdelaorden

@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)

tangshuang avatar Jun 09 '21 14:06 tangshuang