1

I created an angularjs variable parsing example and it works perfectly in my environment. Below highlighting the code of my implementation

var model = $parse("ABC_DEF");
model.assign($scope, chart); //Works successfully

But here i just changed the variable name to "ABC-DEF". Then i implement the variable to the same code of above, but here it shows the exception like assign is not a function in $parse. Below showing the error throwing line of codes

var model = $parse("ABC-DEF");
model.assign($scope, chart); //Not Working- shows assign not a function

What is the reason of this issue?

2 Answers 2

2

ABC-DEF is not a valid variable name in Javascript as the dash is interpreted as the substract operator (related question).

So if you look at the expression guide - angular docs:

Angular expressions are JavaScript-like code snippets that are usually placed in bindings such as {{ expression }}.

Angular is interpreting this expression "ABC-DEF" as a binary function (source), not an assignable expression.

Sign up to request clarification or add additional context in comments.

Comments

0

You may use double quote on that..

example:

$parse("sample['ABC-DEF']").assign($scope, sample);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.