11)What is a module ?
Module in angular JS behaves as a case for the different parts like services, values, filters e.t.c. which were the concepts in angular JS. In HTML wherever we declare the ng-app, making that as start and end with concern closing tag that whole part comes under the module from the view part.
module syntax : var myapp = angular.module('myapp', []);
Using in view :
<div ng-app='myapp'>
//...
</div>
Module in angular JS behaves as a case for the different parts like services, values, filters e.t.c. which were the concepts in angular JS. In HTML wherever we declare the ng-app, making that as start and end with concern closing tag that whole part comes under the module from the view part.
module syntax : var myapp = angular.module('myapp', []);
Using in view :
<div ng-app='myapp'>
//...
</div>
12)What are controllers ?
Controller in angular JS is nothing but a constructor function.
A new controller object is going to be created when angular parser eyes the injected ng-contoller directive to a HTML tag.
The constructor function of a controller needs to be append/attach over the module.
Ex :
var myApp = angular.module('myApp',[]);
myApp.controller('controllerName', ['$scope', function($scope) {
// our required code
}]);
ng-controller is the directive that whih can create the instance of the concern controller and also invokes the $scope object in controller function.
Syntax : <div ng-controller="controllername"> </div>
Controller in angular JS is nothing but a constructor function.
A new controller object is going to be created when angular parser eyes the injected ng-contoller directive to a HTML tag.
The constructor function of a controller needs to be append/attach over the module.
Ex :
var myApp = angular.module('myApp',[]);
myApp.controller('controllerName', ['$scope', function($scope) {
// our required code
}]);
ng-controller is the directive that whih can create the instance of the concern controller and also invokes the $scope object in controller function.
Syntax : <div ng-controller="controllername"> </div>
13)What is $watch ?
$watch is the function of $scope object which was to be as $scope.$watch(). This is the one which observes/listens the changes made over the model variables. It means whenever we do cahnges to a particular model variable it captures and updates all over the places whereever we used.
we can provide our own functionality on change of a variable by using $watch. To know more regarding this please visit my article on "Examle on using $watch";
$watch is the function of $scope object which was to be as $scope.$watch(). This is the one which observes/listens the changes made over the model variables. It means whenever we do cahnges to a particular model variable it captures and updates all over the places whereever we used.
we can provide our own functionality on change of a variable by using $watch. To know more regarding this please visit my article on "Examle on using $watch";
14)How many ng-app's allowed per a document ?
Angular JS will not accept multiple ng-app directves in a HTML document.
While parsing, it listens to only the first faced ng-app directive and starts bootstraping.
In case if we require multiple, we have to call the angular.bootstrap() function mannually.
Angular JS will not accept multiple ng-app directves in a HTML document.
While parsing, it listens to only the first faced ng-app directive and starts bootstraping.
In case if we require multiple, we have to call the angular.bootstrap() function mannually.
15)what is $broadcast ?
$broadcast provides the functionality written in it, through downwards of the controller level hierarchy. The broadcast event can be listened/get by using the $on() function.
For more about $broadcast visit the link : Using $broadcast and $on
$broadcast provides the functionality written in it, through downwards of the controller level hierarchy. The broadcast event can be listened/get by using the $on() function.
For more about $broadcast visit the link : Using $broadcast and $on
16)What is $emit ?
$emit provides the functionality written in it, through upwards of the controller level hierarchy. The $emit event can be listened/get by using the $on() function.
For more about $emit visit the link : Using $emit & $on
$emit provides the functionality written in it, through upwards of the controller level hierarchy. The $emit event can be listened/get by using the $on() function.
For more about $emit visit the link : Using $emit & $on
17)What is singleton in angular JS ?
In general Singleton means reusing the single instance which was created without any creation of instance in further. In angular JS the service object will behave as like the singleton. So, the service in angular JS can be reused wherever we require within application level but its instance will be getting created only once and get shared to all other components where it is needed.
In general Singleton means reusing the single instance which was created without any creation of instance in further. In angular JS the service object will behave as like the singleton. So, the service in angular JS can be reused wherever we require within application level but its instance will be getting created only once and get shared to all other components where it is needed.
18)What is dependency injection in angular JS?
In general, dependency means a component depending on the other component, the purpose can be in any way like getting data or in need of that concern function to be executing. So, it will be a kind getting code redundancy by using the same functionality in all required areas.
To avoid that type of situation, angular provided us some functions or services to use which makes the re-usability of code just by injecting any component or service in the required controller.
Dependency injection in angular JS can be performed by service, factory, value,.,.,etc. These can be injected into a controller to access their functionality.
In general, dependency means a component depending on the other component, the purpose can be in any way like getting data or in need of that concern function to be executing. So, it will be a kind getting code redundancy by using the same functionality in all required areas.
To avoid that type of situation, angular provided us some functions or services to use which makes the re-usability of code just by injecting any component or service in the required controller.
Dependency injection in angular JS can be performed by service, factory, value,.,.,etc. These can be injected into a controller to access their functionality.
To Know more about services follow the link : About services
To Know more about factory follow the link : About facory
To Know more about value follow the link : About value
To Know more about factory follow the link : About facory
To Know more about value follow the link : About value
19) What is ng-disabled ?
ng-disabled is the directive which sets the disabled attribute of the element to be true if the expression’s result is true.
Ex :
Check to disable textbox:<input type="checkbox" ng-model="all"><br>
<input type="text" ng-disabled="all">
In the above example whenever we check the checkbox, the ng-model value “all” of checkbox becomes true and ng-disabled directive makes the textbox in disable mode. In general, the HTML attribute cannot set the disable attribute to false even though we set the element will be in disable mode only.
ng-disabled is the directive which sets the disabled attribute of the element to be true if the expression’s result is true.
Ex :
Check to disable textbox:<input type="checkbox" ng-model="all"><br>
<input type="text" ng-disabled="all">
In the above example whenever we check the checkbox, the ng-model value “all” of checkbox becomes true and ng-disabled directive makes the textbox in disable mode. In general, the HTML attribute cannot set the disable attribute to false even though we set the element will be in disable mode only.
20) What is a directive ?
Directives in angular JS are nothing but the behavior that which we can apply over the HTML elements as like the additional feature and that will be placing over DOM even as like our regular HTML element attributes. Some of the built-in directives in angular JS are like ng-app, ng-controller, ng-repeat...e.t.c. We can even make our own customized directives with specific behavior. All the angular built-in directives are prefixed with “ng”.
Directives in angular JS are nothing but the behavior that which we can apply over the HTML elements as like the additional feature and that will be placing over DOM even as like our regular HTML element attributes. Some of the built-in directives in angular JS are like ng-app, ng-controller, ng-repeat...e.t.c. We can even make our own customized directives with specific behavior. All the angular built-in directives are prefixed with “ng”.
Ex: <body ng-app="myapp">
In the above tag, ng-app is the directive.
No comments:
Post a Comment