Angular JS Flashcards
What is a module?
A module defines an application. It is a container for different parts of an application such as controllers.
How to create a module?
var angular.module(“myApp”, []);
What is the use of [] when declaring a module?
This array is used to contain dependent modules.
What is a view in angular?
A view is used to display data to the users.
How do you create a view?
You create views by writing a template as an HTML page and merging it with data from your model.
What is a model?
A model manages the data, logic and rules of the application.
What is the use of ng-model directive?
The ng-model binds the value of HTML controls (input, select, textarea) to application data.
Write an example of the use of the ng-model to display data in the view. Both html and js part.
<div>
Name:
</div>
var app = angular.module('myApp', []); app.controller('myCtrl', function($scope) { $scope.name = "John Doe"; });
What is the role of $scope object?
The $scope object passed to the controller is the mechanism used to pass model data to views.
Write an example where $scope can be used and display the data in the view.
//create the module var app = angular.module("myApp", []);
//create the controller app.controller("myCtrl", function($scope) { $scope.name = "John"; });
//display data in the view using $scope
<div>
{{ name }}
</div>
What is the use of the ng-app directive?
The ng-app directive tells angular JS that this is the root element of the application. All angular app must have a root element.
What is a controller?
A controller is a javascript object that controls the data of an Angular JS application.
Which directive defines the application controller?
ng-controller
Define a module and a controller.
var app = angular.module("myApp", []); app.controller("myCtrl", function($scope){ $scope.firstName = "John"; $scope.lastName = "Doe"; $scope.fullname = function() { return $scope.lastName + " " + $scope.lastName; }; });
What is a service in angular?
A service is a function or an object that is available for and limited to your angular application.