0

I'm pretty new to angular js. Is there a way to make two directives communicate with each other? I've tried using

require: "^mydirective"

and for some odd reason that's not working

ThomasBrushel
  • 107
  • 3
  • 16

1 Answers1

3

About the directive hints:

[?][^][directiveName].

^ is used to specify which directive controller should be used("inherited from"). So for example a directive <column-item> needs to find the parent directive controller <crtl-grid>.

bottom line ^ indicates angular to seek up the DOM to find the parent directive.

? = it indicates angular that the directive is optional and angular will not throw an exception if not found.

Dalorzo
  • 19,834
  • 7
  • 55
  • 102
  • Can you take a look at this codepen and tell me what I'm doing wrong? https://codepen.io/Brushel/pen/pWbzqM?editors=1011 – ThomasBrushel Sep 22 '17 at 16:03
  • @ThomasBrushel tried to answer your comment on the previous post, but found the the codepen has changed (that's why better to include all the related code in the post and not on external resources), right now the issue is that you don't have `controller` (but you need it to expose an API to other directives) in your `atomHeading` directive, but you have `link` - this is causing the error in the console `Controller 'atomHeading', required by directive 'truncator', can't be found!`. – Stanislav Kvitash Sep 22 '17 at 16:29
  • @StanislavKvitash The pen is right here. I have it truncating. I just need to get the links to show more text and not show if maxCharacters hasn't been reached https://codepen.io/Brushel/pen/LzRdej I forked this so I will have a copy of it – ThomasBrushel Sep 22 '17 at 19:36
  • @ThomasBrushel I've thought, I've helped you to achieve this in your previous posts, [so here is edited codpen](https://codepen.io/anon/pen/OxbLMb?editors=1111), just make some refactoring and move inline js from template to the linking function. – Stanislav Kvitash Sep 23 '17 at 10:13
  • @StanislavKvitash Thank you once again for your help. I do have one more question. Is there a way I can use `%atom-heading` with no attributes? Right now if I use it I get an error `{{ truncatorBindings.text | limitTo: length }}` – ThomasBrushel Sep 25 '17 at 20:40