Home > database >  Why are Angular directives considered classes and not functions?
Why are Angular directives considered classes and not functions?

Time:02-11

The way the Ng directives are used within HTML tags (view) makes them look like functions to be invoked upon rather than instances of a class. Or maybe they are static methods that can be invoked without a class instance. Sorry I am coming from backend, OOP languages (C , Python, Java, C#) and now working to learn Javascript and Typescript and sometimes the philosophy of web-dev is a different paradigm to me.

CodePudding user response:

Angular Directives are classes that are decorated with the @Directive decorator. Angular is as well a very Object Oriented Framework which suites devs coming from other OOP languages.

CodePudding user response:

Well it's true that classes are a template for creating objects. They encapsulate data with code to work on that data. But also - Decorators are the functions that modify JavaScript classes. Directives allow us to extend or manipulate the DOM. At the core, a directive is a function that executes whenever the Angular compiler finds it in the DOM.

  • Related