</>
Skip to content
AngularJS lessons (24/28)

AngularJS — DOM

Element References

app.directive('myDirective', function() {
  return {
    link: function(scope, element, attrs) {
      element.css('color', 'red');
      element.on('click', function() {
        element.toggleClass('active');
      });
    }
  };
});

ng-bind

<p ng-bind="name"></p>
<p ng-bind-html="htmlContent"></p>

jqLite

// AngularJS includes jqLite
element.addClass('active');
element.removeClass('active');
element.hasClass('active');
element.css('color', 'red');
element.text('New text');
element.html('<b>Bold</b>');

Custom Directive DOM

app.directive('resizable', function() {
  return {
    link: function(scope, element, attrs) {
      element.resizable();
      element.on('resizestop', function(event, ui) {
        scope.$emit('resized', ui.size);
      });
    }
  };
});

DOM Events

element.on('click', function(event) {
  scope.$apply(function() {
    scope.handleClick(event);
  });
});

Mini Practice

  1. Manipulate DOM with directives
  2. Use jqLite methods
  3. Handle DOM events
  4. Create custom directives

Up Next

Continue with Tables — AngularJS tables.

Related Topics

Frequently Asked Questions about DOM

What is DOM in AngularJS?

DOM is a fundamental concept in AngularJS. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn DOM?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn DOM.

Why is DOM important in AngularJS?

DOM is essential for AngularJS development. Understanding this concept will help you write better code and solve real-world problems more effectively.