NG-Book-Part-2 Flashcards

1
Q

Two-Way Data Binding

A

Allows us to bind the value of a property inside the private scope of our directive to the value of an attribute available within the DOM.

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

Transclude

A

Transclude is optional. If provided, it must be set to true. Often used to create reusable widgets like modal box or navbar.

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

Compile Phase

A

During the compile phase, Angular slurps up our initial HTML page and begins processing the directives we declared according to the directive definitions we’ve defined within our application’s JavaScript.

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

Run Blocks

A

Run blocks are executed after the injector is created and are the first methods that are executed in any Angular app. Run blocks are the closest thing in Angular to the main method.

Typically, these run blocks are places where we’ll set up event listeners that should happen at the global scale of the app.

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

$routeProvider

A

Using the $routeProvider, we can take advantage of the browser’s history navigation and enable users to bookmark and share specific pages, as it uses the current URL location in the browser.

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

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

ng-view

A

is a special directive that’s included with the ngRoute module. Its specific responsibility is to stand as a placeholder for $route view content.

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

What 2 methods are used to declare routes?

A

the when method and the otherwise method.

The when method takes two parameters (when(path, route)).

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

Route Example

A
angular.module('myApp', [])
  config(['$routeProvider', 
    function($routeProvider) { 
      $routeProvider
        .when('/', { 
          templateUrl: 'views/home.html',
          controller: 'HomeController'
     }); 
}]);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

$Location Service

A

AngularJS provides a service that parses the URL in the address bar and gives you access to the route of the current path of your applications.

It provides a nicer interface to the window.location JavaScript object and integrates directly with our AngularJS apps.

We’ll use whenever we need to provide a redirect internal to our app, such as redirecting after a user signs up, changes settings, or logs in.

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

replace()

A

If you want to redirect completely without giving the user the ability to return using the back button (it’s useful for times when a redirect occurs after they are redirected, for instance a redirect after login).

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

Routing Modes

A

refers specifically to the format of the URL in the browser address bar.

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

Hashbang Mode

A

http://yoursite.com/#!/inbox/all

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

HTML5 Mode

A

This mode makes your URLs look like regular URLs.

http://yoursite.com/inbox/all

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

Dependency Injection

A

is a design pattern that allows for the removal of hard-coded dependencies, thus making it possible to remove or change them at run time.

This ability to modify dependencies at run time allows us to create isolated environments that are ideal for testing.

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

ngMin

A

tool that allows us to alleviate the responsibility to define our dependencies explicitly.It walks through our Angular apps and sets up dependency injection for us.

Installation
$ npm install -g ngmin

Using
$ ngmin input.js output.js

If we’re using Grunt, we can install the grunt-ngmin Grunt task. If we are using Rails, we can use the Ruby gem ngmin-rails.

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

Services

A

Are singleton objects that are instantiated only once per app (by the $injector) and lazy-loaded (created only when necessary).

They provide a method for us to keep data around for the lifetime of the app and communicate across controllers in a consistent manner.

17
Q

Register a service

A
There are several ways to create and register a service with the $injector.
The most common and flexible way to create a service uses the angular.module API factory:
angular.module('myApp.services', [])
  .factory('githubService', function() {
    var serviceInstance = {};
    // Our first service
    return serviceInstance;
  });
18
Q

$timeout service

A

If we don’t include a delay, we’ll end up calling the API for every keystroke that is entered into the input.

19
Q

5 different methods for creating services

A
factory() 
service() 
constant() 
value() 
provider()
20
Q

The factory() function takes two arguments:

A

name (string)

This argument takes the name of the service we want to register.

getFn (function)

21
Q

Why use provider() over factory?

A

If we want to be able to configure the service in the config() function, we must use provider() to define our service.

22
Q

constant()

A

let’s say we want to set an apiKey for a back-end service. We can store that constant value using constant().

angular.module(‘myApp’)
.constant(‘apiKey’, ‘123123123’)

23
Q

Value()

A

If the return value of the $get method in our service is a constant, we don’t need to define a full-blown service with a more complex method.

angular.module(‘myApp’)
.value(‘apiKey’, ‘123123123’);

24
Q

When to Use Value or Constant?

A

The major difference between the value() method and the constant() method is that you can inject a constant into a config function, whereas you cannot inject a value.

25
Q

$http service

A

is simply a wrapper around the browser’s raw XMLHttpRequest object.

The $http service is a function that takes a single argument: a configuration object that is used to generate a HTTP request.

The function returns a promise that has two helper methods: success and error.

26
Q

$http shortcut methods

A
get()
   $http.get('/api/users.json');
delete()
url(string)
head()
jsonp()
  $http
    .jsonp("/api/users.json?callback=JSON_CALLBACK"); 
post()
put()
27
Q

Interceptors

A

Is middleware for the $http service that allow us to inject logic into the existing flow of the app.

At their core, interceptors are service factories that we register through the $httpProvider by adding them to the $httpProvider.interceptors array.

There are four types of interceptors – two success interceptors and two rejection interceptors:

28
Q

What are the 4 types of Interceptors?

A

Request
Response
requestError
responseError

29
Q

How to register an Interceptor?

A

angular.module(‘myApp’)
.config(function($httpProvider) { $httpProvider.interceptors.push(‘myInterceptor’);
});

30
Q

$resource

A

This service creates a resource object that allows us to intelligently work with RESTful server-side data sources. It service allows us to turn our $http requests into simple methods like save or update.

bower install –save angular-resouce

31
Q

$resource htttp methods

A

Get Methods:
get(params, successFn, errorFn)
query(params, successFn, errorFn)

Non Get Mehods:
save(params, payload, successFn, errorFn)
delete(params, payload, successFn, errorFn)
remove(params, payload, successFn, errorFn)

32
Q

Promise

A

A promise is a method of resolving a value (or not) in an asynchronous manner. Promises are objects that represent the return value or thrown exception that a function may eventually provide.

33
Q

Why Promise?

A

Escaping from callback hell is just one by-product of using promises. The real point of promises is to make asynchronous functions look more like synchronous ones. With synchronous functions, we can capture both return values and exception values as expected.