Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Upgrade from 1.4.7 to 1.4.9: Getting Error: $compile:nonassign Non-Assignable Expression #13967

Closed
momoadeli opened this issue Feb 7, 2016 · 2 comments

Comments

@momoadeli
Copy link

I've tracked this down and fixed it too. However, not sure if this is tightened AJS 1.4.9 code or a discarded 'feechure' from before. Basically, in 1.4.7 it was allowed to 'optionally' pass an isolate scope attribute ('=') to a directive and still assign a value (object literal) to it inside the directive if I didn't pass it in. In 1.4.9, however, if I don't pass the 'optional' attribute, I get the above error and, to fix it, I must pass the attribute with an empty object literal assigned.

Below is simple pseudocode for A: WORKED (1.4.7) and B: WORKS w/Fix ( after 1.4.9 I get error above).

A: WORKED:(1.4.7. I don't need to pass optional attribute to directive and yet can assign it inside directive)
mydirective.js:

...scope: {attrObjectLiteral:'='}......   //isolate scope attr definition
....
$scope.attrObjectLiteral = someObjectLiteral;   // assigned isolate scope attr to some data
html usage: 

html:

<my-directive></my-directive>    //sometimes I don't need to pass the attribute (works in 1.4.7 an not 1.4.7)
<my-directive attr-object-literal="some.data"></my-directive>    //sometimes I DO need to pass the attr. Works in 1.4.7 and 1.4.9 as well. 

The above worked in 1.4.7 and doesn't work in 1.4.9 (and beyond?). Fix below. Instead of not passing the optional isolate attribute, pass it assigned to an empty object literal.

B: WORKS w/Fix ( after 1.4.9 I get error above. I MUST pass an optional attribute initialized to an empty object literal if I assign an object to it inside the directive.):
mydirective.js:

...scope: {attrObjectLiteral:'='}......   //isolate scope attr definition

$scope.attrObjectLiteral = someObjectLiteral;   // assigned isolate scope attr to some data
html usage: 

html:

<my-directive attr-object-literal="{}"></my-directive>    //sometimes I don't need to pass the attribute (had to pass empty obj literal)
<my-directive attr-object-literal="some.data"></my-directive>    //sometimes I DO need to pass the attr. Works in 1.4.7 and 1.4.9 as well. 

I liked the optionality of the isolate scope attribute. Thoughts?

Thanks!
Mo

@gkalpak
Copy link
Member

gkalpak commented Feb 8, 2016

Duplicate of #13832 and #13937.

tl;dr:
This is working as expected now. The previous behavior was a regression (that took us quite some time to fix). If you want to have optional bindings you should use =?.

@gkalpak gkalpak closed this as completed Feb 8, 2016
@momoadeli
Copy link
Author

Roger that. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants