Angular
Angular
Install Node JS
Install Angular CLI
Create Project
Compile and Run
Node JS is a runtime environment for executing JS outside browser, it will provide us with tools
that will be used by Angular
Angular CLI is a command line tool used to create an Angular project, it provides a boilerplate.
npm install -g @angular/cli@latest
Creating Component
In angular directives we use selector as attributes, other than that in most cases we use HTML
Tag selector
Data Binding
Allows us to communicate between component class and its view template and vice versa.
Pass the data from component class to view template
The data defined in component class is accessed using jinja template
One way
o Component to view
o View to Component
Two way
An instruction to DOM.
Manipulate DOM
Change Behavior
Add/Remove DOM Elements
Components Directive – nothing but component; has template
Attribute Directive – change the appearance or behavior of DOM element; no template
Structural Directive – add or remove DOM elements; no template; * is used for them
ngFor
It is a structural directive, it iterates over a list and creates an HTML element for each item. In
very simple words it is a for each loop
*ngFor="let item of list"
ngIf
It is a structural directive, it uses a condition to add or remove a DOM element. In simple words
it is if statement
*ngIf="expression"
ngStyle
It is an attribute directive used to add inline styling to an html element dynamically based on
expression
[ngStyle]="{expression}"
ngClass
It is an attribute directive used to add CSS class to an html element dynamically based on
expression
[ngClass]="{expression}"
Custom Property Binding & @Input
It is a variable that stores the reference to a DOM element, Component or directive on which it is
used
<input #phone placeholder="phone number" />
<!-- lots of other elements --> <!-- phone refers to the input
element; pass its `value` to an event handler -->
<button type="button" (click)="callPhone(phone.value)">Call</button>
It is used to query and get a reference of DOM element in the component. It returns the first
matching
@ViewChild(‘query’) var : type
The var will have the reference of the first matching DOM element in the View
Params:
query – search query
static – true/false (resolved before/after change)
read – different token