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

require in directive DDO only causes an error if the DDO also includes a link function #11198

Closed
bborowin opened this issue Feb 26, 2015 · 2 comments

Comments

@bborowin
Copy link
Contributor

Repro: make a simple app w/this custom directive:

foo.directive('bar', function() {
  return {
    scope: false,
    require: 'your mom',
    template: '<span>foobar</span>',
    //link: function() {}
  };
});

Expected: compile pukes on require not matched
Actual: everything compiles fine

Related SO question is here

As far as I can tell, it's because the getController function is only called from pre and post, which doesn't happen when a link function is not specified in the DDO.

@Narretz
Copy link
Contributor

Narretz commented Feb 26, 2015

Yeah, you are explicitly requiring the controller into your link function, not the presence of the parent to your directive. I wonder if it would would break many apps, did we tighten require to throw even without a link function?

Sidenote: I can see how this is confusing. I remember, when I first started with angular, I thought require was also a way to make sure a certain directive can only be nested inside another directive, even if the required directive didn't actually define a controller.

@Narretz Narretz added this to the Ice Box milestone Feb 26, 2015
bborowin added a commit to bborowin/angular.js that referenced this issue Feb 27, 2015
To make things less confusing, explicitly state that require WILL NOT cause a compile error if a link function is not specified.

angular#11198
stackoverflow.com/questions/28730346/require-ddo-option-of-angular-directive-does-not-throw-an-error-when-it-should
@bborowin
Copy link
Contributor Author

Thanks! Added a pull request to update the docs: #11206

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

No branches or pull requests

2 participants