angular js21.Explain ng-disabled directive.
ng-disabled directive disables a given control.

In below example, we’ve added ng-disabled attribute to a HTML button and pass it a model. Then we’ve attached the model to an checkbox and can see the variation.

<input type = “checkbox” ng-model = “enableDisableButton”>Disable Button
<button ng-disabled = “enableDisableButton”>Click Me!</button>

22.Explain ng-show directive.
ng-show directive shows a given control.

In below example, we’ve added ng-show attribute to a HTML button and pass it a model. Then we’ve attached the model to a checkbox and can see the variation.

<input type = “checkbox” ng-model = “showHide1”>Show Button
<button ng-show = “showHide1”>Click Me!</button>

23.Explain ng-hide directive.
ng-hide directive hides a given control.

In below example, we’ve added ng-hide attribute to a HTML button and pass it a model. Then we’ve attached the model to a checkbox and can see the variation.

<input type = “checkbox” ng-model = “showHide2”>Hide Button
<button ng-hide = “showHide2”>Click Me!</button>

24.Explain ng-click directive.
ng-click directive represents a AngularJS click event.

In below example, we’ve added ng-click attribute to a HTML button and added an expression to updated a model. Then we can see the variation.

<p>Total click: {{ clickCounter }}</p></td>
<button ng-click = “clickCounter = clickCounter + 1”>Click Me!</button>l

25.How angular.module works?
angular.module is used to create AngularJS modules along with its dependent modules. Consider the following example:

var mainApp = angular.module(“mainApp”, []);
Here we’ve declared an application mainApp module using angular.module function. We’ve passed an empty array to it. This array generally contains dependent modules declared earlier.

26.How to validate data in AngularJS?
AngularJS enriches form filling and validation. We can use $dirty and $invalid flags to do the validations in seamless way. Use novalidate with a form declaration to disable any browser specific validation.

Following can be used to track error.

$dirty − states that value has been changed.

$invalid − states that value entered is invalid.

$error − states the exact error.

27.Explain ng-include directive.
Using AngularJS, we can embed HTML pages within a HTML page using ng-include directive.

<div ng-app = “” ng-controller = “studentController”>
<div ng-include = “‘main.htm'”></div>
<div ng-include = “‘subjects.htm'”></div>
</div>

28.How to make an ajax call using Angular JS?
AngularJS provides $http control which works as a service to make ajax call to read data from the server. The server makes a database call to get the desired records. AngularJS needs data in JSON format. Once the data is ready, $http can be used to get the data from server in the following manner:

function studentController($scope,$http) {
var url = “data.txt”;
$http.get(url).success( function(response) {
$scope.students = response;
});
}

29.What is use of $routeProvider in AngularJS?
$routeProvider is the key service which set the configuration of urls, maps them with the corresponding html page or ng-template, and attaches a controller with the same.

30.What is constant?
constants are used to pass values at config phase considering the fact that value cannot be used to be passed during config phase.

mainApp.constant(“configParam”, “constant value”);

You may also like

Leave a Comment