Installing Material To Angular
Installing Material To Angular
Angular Notes
For install angular npm install -g @angular/cli
Create New Application ng new <project Name>
To Run the Application ng serve
NPM Package Manager
Components
Cmd for creating component ng g component <component_name>
Component decorator inside the component.ts file.
Selector : unique identifier for the component
=> like id of the component
=> using this selector we will use the component
templateUrl => HTML Code
styleUrls => style of the component
LifeCycleHooks 8 :
ngOnChanges()
ngOnInit()
ngDoCheck()
ngAfterContentInit()
ngAfterContentChecked()
ngAfterViewInit()
ngAfterViewChecked()
ngOnDestroy()
1.Whichever lifecycle hooks we want to use first import it in the class
2.Extends the implements interface
3.Implement the method.
Component Communication :
Routing :
Router-outlets
Router module
Named router module
<Router-outlets name=”route1”></Router-outlets>
<Router-outlets name=”route2”></Router-outlets>
=> {path:’cam’,Component:CameraComponent,outlet : ‘outlet-name we
defined’}
Child routing
{
path: '', component: AppLayoutComponent, children: [
{ path: 'users-list',canActivate: [AuthGuard], component:
UsersListComponent, data: { permittedRoles: ['ROLE_ADMIN'] } },
{ path: 'roles-list', canActivate: [AuthGuard], component:
RolesListComponent, data: { permittedRoles: ['ROLE_ADMIN'] }},
{ path: 'privileges-list', canActivate: [AuthGuard], component:
PrivilegesListComponent, data: { permittedRoles: ['ROLE_ADMIN'] } },
{ path: 'hd-config', canActivate: [AuthGuard], component:
CameraConfigComponent, data: { permittedRoles: ['ROLE_IT_OPS']}}
]
}
ngDoCheck() - Detects and acts upon changes that Angular can't or won't detect on its
own.
ngAfterViewInit() - Respond after Angular initializes the component's views and child
views.
Types of directives
Component directives
These form the main class in directives. Instead of @Directive decorator we use
@Component decorator to declare these directives. These directives have a view, a
stylesheet and a selector property.
Structural directives
These directives are generally used to manipulate DOM elements.
<ng-template #ifBlock>
<h1> IF BLOCK </h1>
</ng-template>
<ng-template #elseBlock>
<h1> ELSE BLOCK </h1>
</ng-template>
Switch Case
<div [ngSwitch]=”color”>
<h1 *ngSwitchCase=”’red’”>Red Color</h1>
<h1 *ngSwitchCase=”’green’”>Green Color</h1>
<h1 *ngSwitchDefault>Default Color</h1>
</div>