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

fix($compile): throw an exception when an attribute is unassigned #6064

Closed
wants to merge 1 commit into from

Conversation

panuhorsmalahti
Copy link

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

@caitp
Copy link
Contributor

caitp commented Jan 30, 2014

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

@ghost ghost assigned tbosch Jan 31, 2014
@panuhorsmalahti
Copy link
Author

Okay. Should I work on the documentation and create a new error page for this?

@Narretz
Copy link
Contributor

Narretz commented Jul 12, 2014

I think this should be merged in some way before 1.3 is released.

if (!attrs[attrName]) {
if (optional) {
return;
} else {
Copy link
Member

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(...);

@googlebot
Copy link

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.

@cironunes
Copy link
Member

@panuhorsmalahti could you squash commits into the first one? Can you also add unit tests for this fix?

@panuhorsmalahti
Copy link
Author

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

@googlebot
Copy link

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
@panuhorsmalahti
Copy link
Author

Squashed the commits and synced my fork.

if (optional) {
return;
}
throw Error('Non-assignable model expression: ' + attrs[attrName]
Copy link
Contributor

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

@petebacondarwin
Copy link
Contributor

@panuhorsmalahti Could you update to use $compileMinErr?

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 $compile similar to https://github.com/angular/angular.js/blob/master/test/ng/compileSpec.js#L3482

@IgorMinar
Copy link
Contributor

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?

@Narretz
Copy link
Contributor

Narretz commented Jul 25, 2017

Better PR here: #16129

@Narretz Narretz closed this Jul 25, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants