-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix($compile): throw an exception when an attribute is unassigned #6064
Conversation
I realize that this is more of a match for what the docs say, but the trouble with this is that it is actually a breaking change, as many directives with isolate scopes are not making use of the "?" optional symbol, and simply ignore an attribute if it's undefined. I don't think we're going to be able to merge this fix until 1.3 in a few weeks |
Okay. Should I work on the documentation and create a new error page for this? |
I think this should be merged in some way before 1.3 is released. |
02dc2aa
to
fd2d6c0
Compare
cad9560
to
f294244
Compare
e8dc429
to
e83fab9
Compare
4dd5a20
to
998c61c
Compare
if (!attrs[attrName]) { | ||
if (optional) { | ||
return; | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need the else
statement since the `ìf`` returns.
So that you could do:
if (optional) return;
throw new Error(...);
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project, in which case you'll need to sign a Contributor License Agreement (CLA) at https://cla.developers.google.com/. If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check the information on your CLA or see this help article on setting the email on your git commits. Once you've done that, please reply here to let us know. If you signed the CLA as a corporation, please let us know the company's name. |
@panuhorsmalahti could you squash commits into the first one? Can you also add unit tests for this fix? |
@googlebot, I wonder why that is. The email in the commit was '[email protected]', which is in the CLA. I added my GitHub account name to the CLA now. |
CLAs look good, thanks! |
Documentation states that NON_ASSIGNABLE_MODEL_EXPRESSION exception should be thrown if a two-way attribute doesn't exist. This commit adds a simple test and throws an error if the property is missing. Note that the documentation should probably be updated and a different exception should be thrown using minErr. This commit refers to issue angular#6060
933ca7b
to
ca16eac
Compare
Squashed the commits and synced my fork. |
if (optional) { | ||
return; | ||
} | ||
throw Error('Non-assignable model expression: ' + attrs[attrName] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We prefer to use minErr
when throwing errors... we may need to create a new error code.
throw $compileMinErr('reqattr',
"Attribute '{0}' used with directive '{1}' is not optional!",
attrName, newIsolateScopeDirective.name);
@panuhorsmalahti Could you update to use We will need a new error info document in https://github.com/angular/angular.js/tree/master/docs/content/error/%24compile explaining what this error means and how to fix it. Also the PR will need a unit test for |
During the fixit#1 a patch was created by @vlad (I believe) to address this during compilation not linking and do it for all isolate scope mapping modes (=,&,@). That approach is preferable to this one. @vlad, I don't see your PR with this change. can you send it to us and mention that it's part of fixit please? |
Better PR here: #16129 |
Documentation states that NON_ASSIGNABLE_MODEL_EXPRESSION exception should be thrown if
a two-way attribute doesn't exist. This commit adds a simple test and throws an error
if the property is missing. Note that the documentation should probably be updated
and a different exception should be thrown using minErr.
This commit refers to issue #6060