-2

I'm new to angular, while learning angular from it's offical docs I didn't get what is a directive context and a exported directive context.

Can anyone please help me out what is it and how it works... Thank you in advance.

Jay Bansod
  • 29
  • 4
  • "Context" in this case refer to the variables that a directive can access to. For example, ngFor, you have index, first, last -> that's the context defined within the directive and they're "exported" for you to use. – Jimmy Nov 20 '22 at 13:00
  • Is that mean a directive internally manages a bunch of variables in his context and some of them are exported out to our use... – Jay Bansod Nov 20 '22 at 13:57
  • yes, you can say that, the ngFor let you use first, last and those variables/internal state is reflected by your input/express (ngFor="let a of X" - first/last depends on X) – Jimmy Nov 20 '22 at 14:00

1 Answers1

0

The official docs shows good what a directive is and how you can using it. Here is a Stackblitz example how a directive works.

And here is the guideline.

With a directive you have access to its element. Examples are available on the official docs (see link), too.

enter image description here

Greetings, Flo

Flo
  • 2,232
  • 2
  • 11
  • 18