Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9013231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:12:33+00:00 2026-06-16T03:12:33+00:00

I have spent quite a lot of time reading through AngularJS documentation and several

  • 0

I have spent quite a lot of time reading through AngularJS documentation and several tutorials, and I have been quite surprised at how unapproachable the documentation is.

I have a simple, answerable question that may also be useful to others looking to pick up AngularJS:

What is an AngularJS directive?

There should be a simple, precise definition of a directive somewhere, but the AngularJS website offers these surprisingly useless definitions:

On the home page:

Directives are a unique and powerful feature available in AngularJS. Directives let you invent new HTML syntax, specific to your application.

In the developer documentation:

Directives are a way to teach HTML new tricks. During DOM compilation directives are matched against the HTML and executed. This allows directives to register behavior, or transform the DOM.

And there is a series of talks about directives which, ironically, seem to assume the audience already understands what they are.

Would anyone be able to offer, for clear reference, a precise definition of what a directive is that explains:

  1. What it is (see the clear definition of jQuery as an example)
  2. What practical problems and situations it is intended to address
  3. What design pattern it embodies, or alternatively, how it fits into the purported MVC/MVW mission of AngularJS.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:12:35+00:00Added an answer on June 16, 2026 at 3:12 am

    What it is (see the clear definition of jQuery as an example)?

    A directive is essentially a function† that executes when the Angular compiler finds it in the DOM. The function(s) can do almost anything, which is why I think it is rather difficult to define what a directive is. Each directive has a name (like ng-repeat, tabs, make-up-your-own) and each directive determines where it can be used: element, attribute, class, in a comment.

    † A directive normally only has a (post)link function. A complicated directive could have a compile function, a pre-link function, and a post-link function.

    What practical problems and situations is it intended to address?

    The most powerful thing directives can do is extend HTML. Your extensions are a Domain Specific Language (DSL) for building your application. E.g., if your application runs an online shopping site, you can extend HTML to have “shopping-cart”, “coupon”, “specials”, etc. directives — whatever words or objects or concepts are more natural to use within the “online shopping” domain, rather than “div”s and “span”s (as @WTK already mentioned).

    Directives can also componentize HTML — group a bunch of HTML into some reusable component. If you find yourself using ng-include to pull in lots of HTML, it is probably time to refactor into directives.

    What design pattern does it embody, or alternatively, how does it fit into
    the purported MVC/MVW mission of angularjs

    Directives are where you manipulate the DOM and catch DOM events. This is why the directive’s compile and link functions both receive the “element” as an argument. You can

    • define a bunch of HTML (i.e., a template) to replace the directive
    • bind events to this element (or its children)
    • add/remove a class
    • change the text() value
    • watch for changes to attributes defined in the same element (actually it is the attributes’ values that are watched — these are scope properties, hence the directive watches the “model” for changes)
    • etc.

    In HTML we have things like <a href="...">, <img src="...">, <br>, <table><tr><th>. How would you describe what a, href, img, src, br, table, tr, and th are? That’s what a directive is.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have struggled a lot spent quiet a lot of time but unable to
I don't spend a whole lot of time in MySQL, but I have been
While profiling an app, realise that quite a lot of time (37%) is spent
I've spent a lot of time working in Django, and have grokked the framework
I have spent a lot of google time on this and im not sure
I am new to Entity Framework but have spend a lot of time reading
So i am using varnish for the first time. i have spent quite some
I have spent 1 week studying objective C. Now I am quite confused at
Have spend quite some time to learn Sencha touch, just like an evaluation about
I have spent several days now researching Hibernate and have several small questions about

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.