NG-BOOK Flashcards

1
Q

AngularJS

A

client-side technology, written entirely in JavaScript. a “structural framework for dynamic web apps.”

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

Dirty Checking

A

is a relatively efficient approach to checking for changes on a model. Every time there could be a potential change, Angular will do a dirty check inside its event loop.

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

Event Loop

A

???

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

$scope object

A

The $scope object is simply a JavaScript object whose properties are all available to the view and with which the controller can interact.

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

Best Data Binding Practices

A

it’s considered a best-practice in Angular to bind references in the views by an attribute on an object, rather than the raw object itself.

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

Module

A

a module is the main way to define an AngularJS app. The module of an app is where we’ll contain all of our application code.

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

module setter method

A

angular.module(‘myApp’, []);

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

module getter method

A

angular.module(‘myApp’)

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

Scope

A

Scopes serve as the glue between the controller and the view. Scopes are objects that contain functionality and data to use when rendering the view.

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

$rootScope

A

The $rootScope is the eventual parent of all $scope objects.

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

$digest loop

A

The loop is made up of two smaller loops which process $evalAsyncqueue and the $watch list. The $digest loop keeps iterating until the model stabilizes, which means that the $evalAsync queue is empty and the $watch list does not detect any changes.

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

Controllers

A

The controller in AngularJS is a function that adds additional functionality to the scope of the view. We use it to set up an initial state and to add custom behavior to the scope object. When we create a new controller on a page, Angular passes it a new $scope.

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

One major distinction between AngularJS and other JavaScript frameworks.

A

frameworks is that the controller is not the appropriate place to do any DOM manipulation or formatting, data manipulation, or state maintenance beyond holding the model data. It is simply the glue between the view and the $scope model.

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

Controller Hierarchy (Scopes Within Scopes)

A

With the exception of isolate scopes, all scopes are created with prototypal inheritance, meaning that they have access to their parent scopes.

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

Expressions

A

All expressions are executed in the context of the scope and have access to local $scope variables. An expression doesn’t throw errors if it results in a TypeError or a ReferenceError. They do not allow for any control flow functions (conditionals; e.g., if/else). They can accept a filter and/or filter chains.

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

$watch

A

$watch function will monitor a property on the $scope. When it changes in any way, it will call the corresponding function.

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

Filters

A

In AngularJS, a filter provides a way to format the data we display to the user. Angular gives us several built-in filters as well as an easy way to create our own. We invoke filters in our HTML with the | (pipe) character inside the template binding characters {{ }}. {{ 123.456789 | number:2 }}

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

Filter filter

A

The filter filter selects a subset of items from an array of items and returns a new array. {{ [‘Ari’, ‘Lerner’, ‘Likes’, ‘To’, ‘Eat’, ‘Pizza’] | filter:’e’ }} <!-- [&quot;Lerner&quot;,&quot;Likes&quot;,&quot;Eat&quot;] -->

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

Filter filter limitTo

A

{{ San Francisco is very cloudy | limitTo:3 }} <!-- San -->

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

novalidate flag

A

It is usually a great idea to use the novalidate flag on the form element, as it prevents the browser from natively validating the form.

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

Required

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

Minimum Length

A

To validate that a form input input is at least a certain {number} of characters, we add the AngularJS directive ng-minlength=”{number}”

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

Maximum Length

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

Matches a Pattern

A

To ensure that an input matches a regex, we can use ng-pattern=”/PATTERN/”:

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

Email

A

To validate an email address in an input field, we simply set the input type to email, like so:

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

Number

A

To validate an input field has a number, we set the input type to number:

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

URL

A

To validate an input field has a number, we set the input type to number:

28
Q

Control Variables in Forms

A

formName.inputFieldName.$pristine; formName.inputFieldName.$dirty; formName.inputFieldName.$valid; formName.inputFieldName.$invalid;

29
Q

$error object

A

This object contains all of the validations on a particular form and a record of whether they are valid or invalid. To get access to this property, use the following syntax: formName.inputfieldName.$error

30
Q

form classes

A

1 .ng-pristine {}

2 .ng-dirty {}

3 .ng-valid {}

4 .ng-invalid {}

31
Q

HTML Document

A

An HTML document is a plain text document that contains structure and may be styled through CSS or manipulated with JavaScript.

32
Q

HTML Node

A

An HTML node is an element or chunk of text nested inside another element. All elements are also nodes; however, a text node is not an element.

33
Q

HTML Element

A

An element comprises an opening tag and a closing tag.

34
Q

HTML Tag

A

An HTML tag is responsible for marking the beginning and end of an element. A tag itself is declared using angle brackets.

35
Q

HTML Attributes

A

To provide additional information about an element, HTML elements can contain attributes. These attributes are always set in the opening tag. We can set them in a key-value pair, like key=”value”, or as only a key.

36
Q

Directives

A

The simplest way to think about a directive is that it is simply a function that we run on a particular DOM element. A directive is defined using the .directive() method, one of the many methods available on our application’s Angular module.

37
Q

built-in-directives

A

A built-in directive is one that ships out of the box with Angular. All built-in directives are prefixed with the ng namespace.

38
Q

directive format

A

we declare the directive in HTML using my-directive, the directive definition must be myDirective. angular.module(‘myApp’, []) .directive(‘myDirective’, function() { return { restrict: ‘E’, template: ‘Click me to go to Google’ } });

39
Q

Declaring Our Directive with an Expression

A

<!-- directive: my-directive someExpression -->

40
Q

Isolate Scope

A

an isolate scope is completely separate from the current scope of the DOM. In order to set properties on this fresh object, we’ll need explicitly pass in data via attributes, similar to the way we pass arguments into a method in JavaScript or Ruby. The main use case for such directives is reusable widgets that can be shared and used in unexpected contexts without polluting the scope around them or having their internal scope corrupted inadvertently.

41
Q

ng-disabled

A

Use ng-disabled to bind the disabled attribute to form input fields. A Button

42
Q

Basic ng Attribute directives

A

ng-href ng-src ng-disabled ng-checked ng-readonly ng-selected ng-class ng-style

43
Q

ng-href

A

When dynamically creating a URL from a property on the current scope, always use ng-href instead of href.

44
Q

ng-src

A

Angular will tell the browser to NOT fetch the image via the given URL until all expressions provided to ng-src have been interpolated.

45
Q

ng-app

A

Placing ng-app on any DOM element marks that element as the beginning of the $rootScope. $rootScope is the beginning of the scope chain, and all directives nested under the ng-app in your HTML inherit from it.

46
Q

ng-controller

A

use ng-controller, which is a built-in directive whose purpose is to provide a child scopes for the directives that are nested inside. We’ll use this directive to place a controller on a DOM element. ng-controller takes a single argument.

47
Q

JavaScript objects are either copy by value or copy by reference.

A

String, Number, and Boolean are copy by value. Array, Object, and Function are copy by reference.

48
Q

ng-include

A

Use ng-include to fetch, compile, and include an external HTML fragment into your current application.

49
Q

ng-switch

A

We use this directive in conjunction with ng-switch-when and on=”propertyName” to switch which directives render in our view when the given propertyName changes.

And the winner is

{{ person.name }}

50
Q

ng-view

A

The ng-view directive sets the view location in the HTML where the router will manage and place the view elements for different routes.

51
Q

ng-if

A

Use ng-if to completely remove or recreate an element in the DOM based on an expression. ng-if differs from ng-show and ng-hide in that it actually removes and recreates DOM nodes, rather than just showing and hiding them via CSS.

52
Q

ng-repeat

A

Use ng-repeat to iterate over a collection and instantiate a new template for each item in the collection.

53
Q

ng-bind

A

Although we can use the {{ }} template syntax within our views (Angular interpolates these), we can mimic this behavior with the ng-bind directive. use ng-controller, which is a built-in directive whose purpose is to provide a child scopes for the directives that are nested inside. We’ll use this directive to place a controller on a DOM element. ng-controller takes a single argument:

54
Q

ng-cloak

A

An alternative to using the directive ng-bind to prevent a flash of unrendered content is to use ng-cloak on the element containing {{ }}:

{{ greeting }}

55
Q

ng-bind-template

A

Similar to the ng-bind directive, we can use the ng-bind-template directive if we want to bind multiple expressions to the view. ng-bind-template=”{{ message }} {{ name }}”>

56
Q

ng-model

A

The ng-model directive binds an input, select, textarea, or custom form control to a property on the surrounding scope. The bottom line is to always have a . in your ng-models.

57
Q

ng-show and ng-hide

A

ng-show and ng-hide show or hide the given HTML element based on the expression provided to the attribute.

2 + 2 isn’t 5, don’t show
2 + 2 isn’t 5, don’t hide

58
Q

ng-form

A

We use ng-form when we need to nest a form within another form. The normal HTML tag doesn’t allow us to nest our forms, but ng-form will.

59
Q

ng-click

A

Use ng-click to specify a method or expression to run on the containing scope when the element is clicked.

60
Q

ng-select

A

Use the ng-select directive to bind data to an HTML element. ng-options takes a comprehension expression for its attribute value, which is just a fancy way of saying it can take an array or an object and loop over its contents to provide the options available when using the select tag.

61
Q

ng-submit

A

We use ng-submit to bind an expression to an onsubmit event. This directive also prevents the default action (sending the request and reloading the page), but only if the form does not contain an action attribute.

62
Q

ng-class

A

Use ng-class to dynamically set the class of an element by binding an expression that represents all classes to be added. Duplicate classes will not be added.

63
Q

.directive() method

A

A directive is defined using the .directive() method, one of the many methods available on our application’s Angular module. angular.module(‘myApp’) .directive(‘myDirective’, function($timeout, UserDefinedService) { // directive definition goes here }) The directive() method takes two arguments: name(string) factory_function(function)

64
Q

factory_function

A

The factory function returns an object that defines how the directive behaves.

65
Q

A JavaScript object is made up of keys and values.

A

When the value for a given key is set to a string, boolean, number, array, or object, we call the key a property. When we set the key to a function, we call it a method.

66
Q

Restrict(string)

A

restrict is an optional argument. It is responsible for telling Angular in which format our directive will be declared in the DOM.