1. Question:What are Expressions in AngularJS? 

    Answer
    AngularJS expressions are much like JavaScript expressions, placed inside HTML templates by using double braces such as: {{expression}}. AngularJS evaluates expressions and then dynamically adds the result to a web page. Like JavaScript expressions, they can contain literals, operators, and variables.
    
    There are some valid AngularJS expressions:
    - {{ 1 + 2 }}
    - {{ x + y }}
    - {{ x == y }}
    - {{ x = 2 }}
    - {{ user.Id }}






    1. Report
  2. Question:How AngularJS expressions are different from the JavaScript expressions? 

    Answer
    AngularJS expressions are much like JavaScript expressions but they are different from JavaScript expressions in the following ways:
    1. Angular expressions can be added inside the HTML templates.
    2. Angular expressions doesn't support control flow statements (conditionals, loops, or exceptions).
    3. Angular expressions support filters to format data before displaying it.






    1. Report
  3. Question:What are Directives in AngularJS? 

    Answer
    AngularJS directives are a combination of AngularJS template markups (HTML attributes or elements, or CSS classes) and supporting JavaScript code. The JavaScript directive code defines the template data and behaviors of the HTML elements.
    
    AngularJS directives are used to extend the HTML vocabulary i.e. they decorate html elements with new behaviors and help to manipulate html elements attributes in interesting way.
    
    There are some built-in directives provided by AngularJS like as ng-app, ng-controller, ng-repeat, ng-model etc.






    1. Report
  4. Question:What is the role of ng-app, ng-init and ng-model directives? 

    Answer
    The main role of these directives is explained as: 
    - ng-app - Initialize the angular app. 
    - ng-init - Initialize the angular app data. 
    - ng-model - Bind the html elements like input, select, text area to angular app model.






    1. Report
  5. Question:How to create custom directives in AngularJS? 

    Answer
    You can create your own custom directive by using following syntax:
    var app = angular.module('app', []); 
    //creating custom directive syntax app.directive("myDir", function () { return {  restrict: "E", 
    //define directive type like E = element, A = attribute, C = class, M = comment  scope: { //create a new child scope or an isolate scope 
     title: '@' //@ reads the attribute value,//= provides two-way binding, //& works with functions
     },template: "<div>{{ myName }}</div>",// define HTML markup 
       templateUrl: 'mytemplate.html', //path to the template, used by the directive    replace: true |   false, // replace original markup with template yes/no 
       transclude: true | false, // copy original HTML content yes/no 
       controller: function (scope) { //define controller, associated with the directive template //TODO: }, 
     link: function (scope, element, attrs, controller) {//define function, used for DOM manipulation //TODO: 
        } 
       } 
    });






    1. Report
Copyright © 2025. Powered by Intellect Software Ltd