Angular: Directives, Expressions, and Controllers

Posted by Christopher Baptiste on October 15, 2020

What is a Directive?

In Agular, a directive is a marker on a DOM element that expands html in a certain manner. Directives can tell AngularJS to attach a specific behavior to a DOM element or they can completely transform an element and its children. Angular comes with several built-in directives, and we can also create our own custom ones. For example, the ng-init directive initializes variables in AngularJS, take a look at the example below:

What is an Expression?

An expression in AngularJS is very similar to an expression in Javascript inside of curly braces. AngularJS evaluates the expression and binds the data to html. Take a look below:

What is a Controller?

A Controller is a Javascript function that maintains tha application’s data using the $cope object. In Angular, the ng-controller directive is used to specify a controller in an application. Take a look an example below: