Angular Material
Angular Material
0
ANGULAR 4 BASICS
What is Angular (Angular 2)?
• Data binding is done with no new directives. We bind to attributes of html elements.
• Simpler API
Building Blocks
2. Components
3. Templates
4. Metadata
5. Data binding
6. Directives
7. Services
8. Dependency injection
Module
• Angular application is a collection of many individual models.
• It contains code that can be export to another module or can be imported by other modules
• Angular framework is a collection of modules
Module
• A module is a class that is decorated with @NgModule decorator
• Every application contains at least one module called root module, conventionally called as
AppModule.
• NgModule decorator provides information about module using properties listed below:
• Declaration – classes that belong to this module. They may be components, directives and pipes.
• Imports – Specifies modules whose exported classes are needed in this module.
• Bootstrap – Specifies the main application view – root component. It is the base for the rest of the
application.
Module Example
• A component may depend on services that are injected using dependency injection.
• Components are decorated with @Component decorator through which we specify template and
selector (tag) related to component.
• FirstComponent.ts
• import { Component } from '@angular/core';
• @Component({
• selector: 'my-first’, // tag to be used in view
• templateUrl : './first.component.html'
• })
• export class FirstComponent {
• title : string = “KLFS Solutions";
• }
• Templates
• You define a component's view with its companion template.
• A template is a form of HTML that tells Angular how to render the component.
• Metadata
• Metadata provided using decorators inform Angular how to process a class.
• For example, @Component decorator tells Angular to treat a class as a component and also provides
additional information through attributes of decorator (like selector, template etc.)
• Data Binding
• Data from objects should be bound to HTML elements and vice-versa, known as data binding.
• Structural directives alter layout by adding, removing, and replacing elements in DOM.
• Attribute directives alter the appearance or behavior of an existing element. In templates they
look like regular HTML attributes, hence the name.
• *ngFor and *ngIf are structural directives.
• Dependency Injection
• Dependency injection is a way to supply a new instance of a class with the fully-formed
dependencies it requires.
• An injector contains instances of services. It injects them into other services and components as
and where they are needed.
Services
Router
• It decides which view should appear based on URL
Angular 4 setup
• It is important to setup development environment for Angular in your system. Here are the
steps to take up:
• Install Node.js and NPM
• Install Node.js and NPM. Node.js is used run JavaScript on server and provide environment
for build tools.
• NPM is used to manager packages related to JavaScript libraries. NPM itself is a Node
application.
• To install, go to https://nodejs.org/en/download and installer (.msi) for 32-bit or 64-bit. Do the
same for other platforms like Mac etc.
• Run .MSI file to install Node.js into your system. It is typically installed into c:\Program
Files\nodejs folder.
• Quickstart seed, maintained on github, is quick way to get started with Angular local development.
• Follow the steps below to clone and launch quickstart application.
• 1. Create a folder for project. Let us call it demo.
• 2. Download quickstart seed from https://github.com/angular/quickstart/archive/master.zip
• 3. Extract quickstart-master.zip into folder created above.
Array that
contains list of
components to
be used in in
this component
Adding style to the component
Interpolation
• Intepolation can be done by using {{ name }}
• Or by using [ ] example src attribute of img tag // note : don’t add end tag
Difference between property and Attribute
• The value of property can be changed
• But the value of attribute cannot be changed
#mytext is a
refernce to
text box
To refer event
• Number:1.2-3 – indicates 1 digit before decimal min 2 after decimal maximum 3 after decimal
if number of digits are more rounding of number will be done
• Currency transformation
• {{8.99 | currency : ‘EUR’}} ----- EUR 8.99
• {{8.99 | currency : ‘EUR’:true}} – Euro symbol will be displayed
• Date transformation
• You may use mediumTime
Drawbacks of not using DI