https://codecraft.tv/courses/angular/
#=============================================================================
- @angular/core
- NgModule
- Creating Angular Module
- Component
- Creating Angular Component
- Injectable, for Service
- Pipe, Creating Pipe
- Directive, creating Custom Directive
- HostListener, for defining custom event in Directive
- Renderer, for defining custom rendering for Directive UI
- ElementRef, for referring DOM element in Directive
- NgModule
- @angular/compiler, the Angular Compilation Services
- Developer
- Production, uses Ahead-Of-Time (AOT) compilation
- @angular/common
- The Module Loader and Module Manager for Various Standard Angular Modules
- CommonModule
- The Object that is used to mamage and load depednencies across all custom modules when they are loaded by Main or(Root) module
- @angular/common/http
- New from Angular 4 and Mandatory for Http calls from Angular 6
- CommonModule
- The Module Loader and Module Manager for Various Standard Angular Modules
- @angular/platform-browser
- Provides BrowserModule that manages Angular app in browser
- @angular/platform-browser-dynamic
- Provides 'platformBrowserDynamic()' method to manage
- Databinding, DOM Rendering and any dynamic DOM operations
- Provides 'platformBrowserDynamic()' method to manage
- @angular/forms
- Provides FormsModule for Two-Way Databinding
- ReactiveFormsModule for LOB Forms
- @angular/router
- Provided RouterModule for Routing
- @angular/animation
- rxjs
- Dependency Package used by Angular for Reactive JavaScript to use Observable pattern
- zone.js
- Used by platformBrowserDynamic for Any Browser level errors
#=============================================================================
- They are the objects. They are used for defining additional or predefined behavior to ES 6 classes
- Applied on class, method, member usinf @ sign
- Examples of Decorators in Angular
- @NgModule()
- Container for all Angular Objects like
- Component
- Services
- Pipes
- Directives
- Properties for NgModule
- imports: of the type array, used to import standard Angular modules and Modules from external NG applications in currenr project
- exports: of the type array, used to export components, services, pipes, directives from current application to other NG application
- declarations: of the type array, used to declare components, pipes and directives of current application in module. They are just ref. objects
- providers: of the type array, this provides DI container for all Angular Services of the current project.
- bootstrap: of the type array, contains instances of components from declarations array. These components will be loaded when NG application executes
- Container for all Angular Objects like
- @Component()
- Applied on ES 6 class to use it as NG Component.
- It has following properties
- selector: The custom HTML Tag. This will be used to render the component.
- template: Inline HTML Template
- templateUrl: External HTML file
- style and styleUrls: Inline and external CSS style files
- @Pipe()
- @Injectable()
- @HostListener()
- @Directive()
- @Input()
- @Output()
- @ViewChild() #=============================================================================
- @NgModule()
- src
- app
- components
- folder for each component
- app.XXXX.component.ts
- app.XXXX.view.html
- folder for each component
- models
- app.xxxx.model.ts
- app.xxxx.logic.ts
- app.xxxx.constants.ts
- services
- app.xxxx.services.ts
- pipes
- app.xxxx.pipes.ts
- directives
- app.xxxx.directives.ts
- components
- app
#=============================================================================
- Interpolation --> Read-Only {{}}
- Property Binding --> [] =""
- Event Binding --> ()="method()"
- Two-Way Binding
- Property Binding + Event Binding
- [(ngModel)]
- Attribute Directivce used to listen property changes from UI component and Back using ngOnChanges() event
- The 'ngModel' needs FormsModule to be imported in @NgModule from the @angular/forms package
- ngModelChanges will listen to default event of the element
- It will update the element's property
- It will update the component, the ngOnChanges() event of component
- Component will update and it will update the property and all other properties depending on property being updated, the ngDoCheck() event of component
- Component will update UI will all of its updated proeprties
#=============================================================================
What are directives? They are objects used to set custom behavior to Standard DOM elements or can also be used to create custom views in Angular Apps
3 Types of Ditectives
- Component Directive
- Structurla Directive
- Used to add/remove DOM elements dynamically based on conditions
- *ngFor
- *ngIf
- *ngSwitch-ngSwichCase
- Used to add/remove DOM elements dynamically based on conditions
- Attribute Directives
- Custom Attributes for DOM
- ngModel
- formControlName
- Custom Attributes for DOM
#=============================================================================
#Angular for Line-of-Business (LOB) Apps
- Angular Forms
- Template Forms
- Utility Forms e.g. Login
- Use '#' notation to set idnetity of the Element
- <input type="text" #username>
- Reactive Forms aka Model-Driven-Forms aka Data-Driven-Forms
- Used an Object-Model to handle HTML Form as a singe Unit of post
- ReactiveFormsModule, the object for Reactive Forms development
- The is mapped with ngForm
- (onSubmit) is mapped wtih ngSubmit
- The 'FormGroup' object is used to create a collection of FormControls (?)
- FormControl is an editiable element inside FormGroup
- The [formGroup] a attribute directive is used to map with FormGroup
- formControlName is a attribute directive is used to link the editable element with formGroup and Model class properties
- FormGroup is instantiated using Model and its properties linked with FormControl
- let fromGroup = new FormGroup({
- 'KEY': new FormControl(Model.Property)
- });
- FormGroup.value will return 'state' of form
- value that valid or invalid
- FormControl. value will return 'state' of individual element
- ReactiveFormsModule, the object for Reactive Forms development
- Form Validations
- Validators class
- Validation Static methods
- required(AbstractControl)/requiredTrue()
- pattern(RegEx/strring)
- minlength(number)/maxlength(number)
- Validation Static methods
- Validation Rule Definition on UI element
- .controls..dirty
- The element is focused and changed
- !.controls..valid
- The value/element is invalid
- .controls..dirty
- Validation Rule check
- .controls..errors.
- Validation-Ruke
- required
- pattern
- minlength
- maxlength
- Validation-Ruke
- Define validation rules on Model property using
- Validators.compose([Array of Validations])
- .controls..errors.
- Custom Validators
- The method must be static
- The input parameter can be either AbstractControl or Standard Datatype
- If value is valid the return null
- For Invalid value return
- {invalid:true} / {valid:false}
- Validators class
- Used an Object-Model to handle HTML Form as a singe Unit of post
- Template Forms
#=============================================================================
- Components Knows each other based on Parent-Child Relationship
- Use @Input() and @Output() to pass data from Parent to Child and emit event from child to parent respectively
- @Input is applied on public property of child and this can be used for Property-Binding
- @Output is applied on EventEmitter object in Child, this can be used for event binding
- EventEmitter object
- Used to define an event with T as 'Payload', means the data to be emitted when an event is raised and subscribed
- The subscriber will received the payload data using $event a standard object.
- EventEmitter object
- Use @Input() and @Output() to pass data from Parent to Child and emit event from child to parent respectively
- Components does not know each-other
#=============================================================================
- Create a 'lib' folder and create a folder of name 'sharedmodule' in it. This will have following
- app.shared.module.ts
- Angular Module with CommonModule imported in it
- services folder to contain services
- This will be 'root' service
- app.shared.module.ts
- The HttpClientModule from @angular/common/http is used to provide Object Model for HttpClient to perform Http Requests from Angular Application
#=============================================================================
- The @angular/router package, provided following
- The RouterModule, the class used for providing routing Object Model for the application
- The Routes class
- The Route Table, each enrty in route table is 'Route' object
- The Route class
- Following properties
- path: string, represents the Route URI --> Mandatory
- component: , the component to be loaded --> Mandatory
- children: type, child routing
- redirectTo: string, redirect conditionaly to specific URI
- loadChildren: string, path of the lazy loaded module
- data: string | array, used in case of Guarded Routes
- Following properties
- The Router class
- Provides event based routing using 'navigate()' method
- navigate([ROUTE URI])
- Provides event based routing using 'navigate()' method
- The ActivatedRoutes class
- Used for Subscribing to Parameterized Routes
- The 'routerLink' the attribute directive, this accepts an array of information for routing
- <a [routerLink]="['', ,,...]">
- The RouterOutlet component
-
- The container where all components will be rendered
-
#=============================================================================
- WHat is the UI and its behavior?
- Decide the terget element and how it affects it (logic)
- Define properties those will be used to set values for directive
- Declare @Input() decorated properties
- Define event methods
- These methods will execute logic when events are fired on UI element.
- Programming
- The @Directive() decorator
- For attribute directive we use the selector
- select:'[Name]'
- For attribute directive we use the selector
- Input decorated (@Input) properties linked with Directive Selector
- Use the Renderer class to manage DOM Rendering and ElementRef class to refer the DOM element to apply directive effects
- Use @HostListener() decorator to apply on methods those will be executed on events.
- The @Directive() decorator