NG-BOOK Flashcards
AngularJS
client-side technology, written entirely in JavaScript. a “structural framework for dynamic web apps.”
Dirty Checking
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.
Event Loop
???
$scope object
The $scope object is simply a JavaScript object whose properties are all available to the view and with which the controller can interact.
Best Data Binding Practices
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.
Module
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.
module setter method
angular.module(‘myApp’, []);
module getter method
angular.module(‘myApp’)
Scope
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.
$rootScope
The $rootScope is the eventual parent of all $scope objects.
$digest loop
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.
Controllers
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.
One major distinction between AngularJS and other JavaScript frameworks.
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.
Controller Hierarchy (Scopes Within Scopes)
With the exception of isolate scopes, all scopes are created with prototypal inheritance, meaning that they have access to their parent scopes.
Expressions
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.
$watch
$watch function will monitor a property on the $scope. When it changes in any way, it will call the corresponding function.
Filters
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 }}
Filter filter
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’ }} <!-- ["Lerner","Likes","Eat"] -->
Filter filter limitTo
{{ San Francisco is very cloudy | limitTo:3 }} <!-- San -->
novalidate flag
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.
Required
Minimum Length
To validate that a form input input is at least a certain {number} of characters, we add the AngularJS directive ng-minlength=”{number}”
Maximum Length
Matches a Pattern
To ensure that an input matches a regex, we can use ng-pattern=”/PATTERN/”:
To validate an email address in an input field, we simply set the input type to email, like so:
Number
To validate an input field has a number, we set the input type to number: