Hello AngularJS Flashcards

1
Q

What is a module?

A

A module contains the different components of an AngularJS app

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

What is a controller?

A

A controller manages the app’s data.

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

What is an expression?

A

An expression displays values on the page.

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

What is a filter?

A

A filter formats the value of an expression.

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

In which file are modules usually defined?

A

App.js

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

What is the basic syntax for defining a module?

A

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

where myApp is the name of your module.

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

How is a module applied to an html page?

A

By adding the ng-app attribute to the body tag.

<body>

myApp is the name of the module
</body>

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

In which file are controllers usually defined?

A

Controllers are usually defined in their own JS file whose name matches the name of the controller.

A controller called MainController is usually defined in a JS file named MainController.js.

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

What is the basic syntax for defining a controller?

A

app.controller(‘MyController’, [‘$scope’,
function($scope) {
$scope.title = ‘Most Popular in Books’;
$scope.promo = ‘My Promo’;
$scope.product = {
name: ‘The Book of Trees’,
price: 19,
pubdate: new Date(‘2014’, ‘03’, ‘08’)
};
}]);

MyController is the name of the controller

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

How is a controller applied to an html page?

A

By adding the ng-controller tag

<div>

MainController is the name of the controller
</div>

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

How does a controller and its associated HTML page communicate with each other?

A

Using the $scope object

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

How can a controller send data to an HTML page using the $scope object?

A

By defining properties on the $scope variable during or after the definition of the controller.

app.controller(‘MyController’, [‘$scope’,
function($scope) {
$scope.title = ‘Most Popular in Books’;
$scope.promo = ‘My Promo’;
$scope.product = {
name: ‘The Book of Trees’,
price: 19,
pubdate: new Date(‘2014’, ‘03’, ‘08’)
};
}]);

During the definition of the MyController controller, the properties title, promo, and product are defined on the $scope object.

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

How does an HTML page display the properties defined on a $scope object?

A

Using handlebars expressions

<div>
<h1>{{ title }}</h1>
<h2>{{ promo }}</h2>
</div>

title and promo are properties defined on the $scope object during the definition of the MyController controller

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

What is a filter?

A

A filter formats the value of an expression.

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

How are filters applied to expressions?

A

{{ title | uppercase }}

The uppercase filter is being applied to the title property of the $scope object.

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

What filter is used to display a string in uppercase?

A

uppercase

17
Q

What filter is used to display a number as currency?

A

currency

18
Q

What filter is used to format a date?

A

date

19
Q

How can an array of objects defined on a $scope object be displayed on an HTML page?

A

Using the ng-repeat attribute

<div>
<div>
<img></img>
<p>{{ product.name }}</p>
<p>{{ product.price | currency }}</p>
<p>{{ product.pubdate | date }}</p>
</div>
</div>

products is a property on the $scope object that returns an array of objects

20
Q

How can the src attribute of an image be configure using an expression

A

Using the ng-src attribute

<img></img>

cover is a property defined on the product object which is in turn defined on the $scope object or is the iteration variable if this HTML code is placed inside an element with ng-repeat defined

21
Q

What attribute to used to configure which function is called when an element is clicked?

A

ng-click

<p>

plusOne is a function defined on the $scope object
$index is a property available inside ng-repeat loops that returns the value of the current index of the array being iterated</p>

22
Q

What property inside ng-repeat loops returns the index of the current object in the array being iterated?

A

$index

23
Q

What property inside ng-repeat loops returns true if the current object is the first object in the array being iterated ?

A

$first

24
Q

What property inside ng-repeat loops returns true if the current object is the last object in the array being iterated ?

A

$last

25
Q

What property inside ng-repeat loops returns true if the the index of the current object in the array being iterated is even?

A

$even

26
Q

What property inside ng-repeat loops returns true if the the index of the current object in the array being iterated is odd?

A

$odd

27
Q

What value for the date filter is used to print a date in this format (Sep 9, 2015)?

A

mediumDate

Ex:

{{ product.date | date:’mediumDate’ }}

28
Q

What value for the date filter is used to print a date in this format (9/9/2015)?

A

shortDate

Ex:

{{ product.date | date:’shortDate’ }}

29
Q

What value for the date filter is used to print a date in this format (2:00 PM)?

A

shortTime

Ex:

{{ product.date | date:’shortTime’ }}