Jools
Jools

Reputation: 155

AngularJS - Difference between Directives and Templates

can anybody explain the difference between directives and templates in angularjs?

I know that directives can e.g. custom tags. but templates are tags, too. so what is the difference between directive tags or template tags?

Upvotes: 2

Views: 1186

Answers (3)

shanks
shanks

Reputation: 922

A directive is simply a way to define new types of html elements specific to your application. It is a way of teaching html new tricks as some angularjs heads would say. Templates on the other hand are snippets of injectable HTML code that can act as a UI for directives and views.

Directives can be used to create self-containing webpage components/ widgets by feeding it with templates that describe how the widget's UI should look like.

this tutorial really simplified things for me

Upvotes: 1

Jason
Jason

Reputation: 15931

A template is a chunk of HTML, a directive is a "widget" (a self contained functional module), that may include UI, that can be added to a page or template.

It's pretty recursive, as directives can contain templates, and vice-versa.

Upvotes: 1

Sharondio
Sharondio

Reputation: 2614

Templates are not custom tags. Directives are called (either via custom attributes, classes or as a custom element) and contain code for interacting with the DOM and may include templates. Templates are either a string of HTML or a file containing HTML.

Upvotes: 0

Related Questions