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

Directive require doesn't throw without link... #3941

Closed
iammerrick opened this issue Sep 9, 2013 · 7 comments
Closed

Directive require doesn't throw without link... #3941

iammerrick opened this issue Sep 9, 2013 · 7 comments

Comments

@iammerrick
Copy link
Contributor

angular.module('app', []);
angular.module('app').directive('one', function() {
  return {
    require: 'ngModel',
    template: '<div>{{ngModel}}</div>'
  }
});
<div one></div>

This won't throw unless a link function is added to the directive...

http://jsbin.com/ikIpuri/1/edit

@petebacondarwin
Copy link
Contributor

This seems like a reasonable request. We should probably create a noop link function if one is not provided. @IgorMinar & @mhevery - is there any reason why we shouldn't do this?

colincasey added a commit to colincasey/angular.js that referenced this issue Sep 24, 2013
@colincasey
Copy link
Contributor

@petebacondarwin - creating a default noop link function when none has been provided seems to break a couple of compile test cases where transluction, templateUrl and replacement are in the mix so it can't be applied in every situation but does work if checking for the specific scenario outlined above.

@thebigredgeek
Copy link
Contributor

@colincasey @petebacondarwin Why not just dirty check the link member and, if it doesn't exist, simply ignore the function call?

@thebigredgeek
Copy link
Contributor

Also, I seem to be having an issue reproducing any sort of issue. I don't really understand the need for compile to throw an error if link does not exist? Seems like adding rigidity without a particular use case, unless you provide one @iammerrick ?

@iammerrick
Copy link
Contributor Author

Absolutely. What I showed above is a perfectly sound usecase, a directive that composes other directives.

@chrisirhc
Copy link
Contributor

+1 to this. This is important to highlight requirements of a directive during its usage. Right now, I use link: angular.noop to enforce this, but I was hoping in the future I wouldn't have to.

@rodyhaddad rodyhaddad modified the milestones: Backlog, 1.3.0 Aug 20, 2014
@caitp
Copy link
Contributor

caitp commented Sep 9, 2014

I don't see why we should throw here --- there's no reason to need a link function for a directive if you're just using it to add/replace a template to your element.

Not calling link functions that we don't need to is a win, imo --- if someone can convince me otherwise, I'm happy to be convinced

@caitp caitp closed this as completed Sep 9, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants