Angular JS Flashcards

1
Q

What is a module?

A

A module defines an application. It is a container for different parts of an application such as controllers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to create a module?

A

var angular.module(“myApp”, []);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the use of [] when declaring a module?

A

This array is used to contain dependent modules.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a view in angular?

A

A view is used to display data to the users.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you create a view?

A

You create views by writing a template as an HTML page and merging it with data from your model.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a model?

A

A model manages the data, logic and rules of the application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the use of ng-model directive?

A

The ng-model binds the value of HTML controls (input, select, textarea) to application data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Write an example of the use of the ng-model to display data in the view. Both html and js part.

A

<div>
Name:
</div>

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
    $scope.name = "John Doe";
});
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the role of $scope object?

A

The $scope object passed to the controller is the mechanism used to pass model data to views.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Write an example where $scope can be used and display the data in the view.

A
//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>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the use of the ng-app directive?

A

The ng-app directive tells angular JS that this is the root element of the application. All angular app must have a root element.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a controller?

A

A controller is a javascript object that controls the data of an Angular JS application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Which directive defines the application controller?

A

ng-controller

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Define a module and a controller.

A
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope){
$scope.firstName = "John";
$scope.lastName = "Doe";
$scope.fullname = function() {
return $scope.lastName + " " + $scope.lastName;
};
});
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a service in angular?

A

A service is a function or an object that is available for and limited to your angular application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Give an example of the use of a service.

A
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope, $location) {
$scope.myUrl = $location.absUrl();
});

<div>
<p> The url of this page is: </p>
<h3>{{ myUrl }}</h3>
</div>

17
Q

What is dependency injection?

A

Dependency injection is a software design pattern that deals with how the application gets hold of its dependencies.

18
Q

What is data-binding?

A

Data binding is the synchronization of the model and the view.

19
Q

Give an example of data binding.

A
var app = angular.module("myApp", []);
app.controller("myCtrl", function ($scope) {
$scope.firstName = "John";
$scope.lastName = "Doe";
});

<div>
<p></p>
</div>

20
Q

Give an example of two way data binding.

A
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.country = "Mauritius"
});

<div>
Country:
<h1> {{ country }} </h1>
</div>

21
Q

What are the steps to create a two way data binding?

A

Create a module
Create a controller
Add a default data to the controller’s $scope.
Add ng-app and ng-controller to the page.
Create an input using the ng-model directive to input the default data saved in the $scope.
Create an element, for example h1 and add an expression using the element of $scope.

22
Q

What is an angular template?

A

An angular template is written with HTML that contains angular js specific elements and attributes. Angular combines the template with the information from the model and controller to render the dynamic view that the user sees.

23
Q

What is a directive?

A

Angular JS lets you extend HTML with new attributes using directives.

24
Q

Give some example of built in directives?

A

ng-app
ng-controller
ng-bind
ng-model

25
Q

Declare a controller using this instead of $scope.

A

var app = angular.module(“myApp”, []);

//we declare as usual, using using 'this' object instead of 
//$scope
app.controller("myCtrl", function() {
this.title = "Some title";
});

<div>
//myCtrl doesn't exist inside, we use 'main' instance only
{{ main.title }}
</div>