31) List out the components which can be used in AngularJS modules?
- Controller
- Filter
- Provider
- Factory
- Routes
- Service
- Directive
“ng” is the core module in AngularJS and this module will be loaded by default when angular application has started.
<ul>
<li data-ng-repeat="mytestname in names">
{{ mytestname }}
</li>
</ul>
Factory methods are used for creating a directive. It can be invoked only once that is when compiler matches the directive.
35) Can we create a custom directive in AngularJS?
Yes we can create custom directive.
36) How to load select box during page initialization using AngularJS?
Below is the sample code to initialize the select box using AngularJS –
<div ng-controller = “mycontroller” ng-init = “loaddataforselectBox()”>
</div>
37) How AngularJS will automatically be initialized?
AngularJS will be initialized during “DOMContentLoaded” event or during the angular.js file download to browser. Now AngularJS looks for directive – “ng-app”, which is a root compilation for AngularJS.
38) What is the difference between Rootscope and Scope in AngularJS?
- Rootscope – Rootscope is the top most scope and one application can have an only one rootscope and will be shared among all the components.
- Scope - Scope will act like a glue between view and controller and scopes are arranged in hierarchical structure.
39) Give an example for Rootscope in AngularJS?
Rootscope acts like a global variable and below is the sample code for the same –
<html>
<body ng-app="mytestApp">
<div ng-controller="MyFirstController" style="border:2px solid blue; padding:5px">
Hi {{mymsg}}!
<br />
Hi {{myname}}! (rootScope)
</div>
<br />
<div ng-controller="MySecondController" style="border:2px solid green; padding:5px">
Hello {{mymsg}}!
<br />
Hi {{name}}! (rootScope)
</div>
<script src="/lib/angular.js"></script>
<script>
var app = angular.module('mytestApp', []);
app.controller('MyFirstController', function ($scope, $rootScope) {
$scope.msg = 'Good Morning';
$rootScope.name = 'Test My scope';
});
app.controller('MySecondController', function ($scope, $rootScope) {
$scope.msg = 'Good Night';
$scope.CheckName = $rootScope.name;
});
</script>
</body>
</html>
40) Do I need to use Jquery in AngularJS?
No. No need to use Jquery in AngularJS.