NG-Book-Part-2 Flashcards
Two-Way Data Binding
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.
Transclude
Transclude is optional. If provided, it must be set to true. Often used to create reusable widgets like modal box or navbar.
Compile Phase
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.
Run Blocks
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.
$routeProvider
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’]);
ng-view
is a special directive that’s included with the ngRoute module. Its specific responsibility is to stand as a placeholder for $route view content.
What 2 methods are used to declare routes?
the when method and the otherwise method.
The when method takes two parameters (when(path, route)).
Route Example
angular.module('myApp', []) config(['$routeProvider', function($routeProvider) { $routeProvider .when('/', { templateUrl: 'views/home.html', controller: 'HomeController' }); }]);
$Location Service
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.
replace()
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).
Routing Modes
refers specifically to the format of the URL in the browser address bar.
Hashbang Mode
http://yoursite.com/#!/inbox/all
HTML5 Mode
This mode makes your URLs look like regular URLs.
http://yoursite.com/inbox/all
Dependency Injection
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.
ngMin
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.