How can we create a custom directive in Angular?

Till now we have looked in to predefined Angular directives like “ng-controller”,”ng-model” and so on. But what if we want to create our own custom Angular directive and attach it with HTML elements as shown in the below code. <div id=footercompany-copy-right></div> To create a custom directive we need to use the “directive” function to register…

Can we have nested controllers in AngularJS?

YES. We can create nested controllers in AngularJS. Nested controller are defined in hierarchical manner while using in View. Take a look at below code. Here the hierarchy is “MainCtrl -< SubCtrl -< SubCtrl1″. <div ng-controller=”MainCtrl”> <p>{{message}} {{name}}!</p> <div ng-controller=”SubCtrl”> <p>Hello {{name}}!</p> <div ng-controller=”SubCtrl2″> <p>{{message}} {{name}}! Your username is {{username}}.</p> </div> </div> </div>

What is MVC Architecture in AngularJS?

In AngularJS, scope objects are treated as Model. The View is display of model that is your data. And the model gets initialized within a JavaScript constructor function, called Controller in AngularJS. Let take a look at below code to understand it better. <!DOCTYPE html> <html> <head> <script data-require=”angular.js@*” data-semver=”1.3.6″ src=”https://code.angularjs.org/1.3.6/angular.js”></script> <link rel=”stylesheet” href=”style.css” />…

What are controllers in AngularJS?

In Angular, a Controller is a JavaScript constructor function. When a Controller is attached to the DOM via the ng-controller directive, Angular will instantiate a new Controller object, using the specified Controller’s constructor function. The job of a controller is to pass data from the model, to the view or the view can asks for…

What is $rootscope in AngularJS?

The $rootScope is the top-most scope. An app can have only one $rootScope which will be shared among all the components of an app. Hence it acts like a global variable. All other $scopes are children of the $rootScope. Since $rootScope is a global, which means that anything you add here, automatically becomes available in…

What is scope in AngularJS?

A scope is an object that ties a view (a DOM element) to the controller. In the MVC framework, scope object is your model. In other words, it is just a JavaScript object, which is used for communication between controller and view.