
ng new <project> --no-strictng serve --host 0.0.0.0 --disable-host-checkng serve --host 0.0.0.0 --disable-host-check --port 4200ng serve --host 0.0.0.0 --disable-host-check --port 4201npm install --save bootstrap@3- add path to bootstrap.css in
angular.json ng g c <component> --spec falseskip tests oldng g c <component> --skipTests trueskip tests old- Lifecycle
- ngOnChanges: Called after a bound input property changes
- ngOnInit: Called once the component is initialized
- ngDoCheck: Called during every change detection run
- ngAfterContentInit: Called after content (ng-content) has been projected into view
- ngAfterContentChecked: Called every time the projected content has been checked
- ngAfterViewInit: Called after the component’s view (and child views) has been initialized
- ngAfterViewChecked: Called every time the view (and child views) have been checked
- ngOnDestroy: Called once the component is about to be destroyed
ng g d <directive>(<FormArray>this.recipeForm.get('ingredients')).clear();ng g p <pipe>npm install --save @ngrx/storenpm install --save @ngrx/effectsnpm install --save-dev @ngrx/store-devtoolsnpm install --save @ngrx/router-store- Angular Universal
ng add @nguniversal/express-engine --clientProject <projectname>- version < 9
- npm install –save @nguniversal/module-map-ngfactory-loader
- in
app.server.module.ts- import { ModuleMapLoaderModule } from ‘@nguniversal/module-map-ngfactory-loader’
- version > 12
ng add @nguniversal/express-enginenpm run dev:ssr
- NestJS
ng add @nestjs/ng-universal
- Progressive Web Apps (PWA)
ng add @angular/pwa
- VSCode Extensions
- Material Icons Theme
- Angular Essentials John papa
ng add @angular/materialnpm i @angular/cdkng g @angular/material:nav main-navng new angular-shop --create-application=false- Typescript
npm i -g typescriptnpx tsc <filename.ts>npx tsc --init
npm init -y- ``
- ``
- ``
- ``
- ``
- ``
Observables
Observables
import { Component, OnDestroy, OnInit } from '@angular/core';
import { interval, Observable, Subscription } from 'rxjs';
import { map, filter } from 'rxjs/operators'
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit, OnDestroy {
private firstObsSubscription: Subscription;
constructor() { }
ngOnInit() {
//this.firstObsSubscription = interval(1000).subscribe((count) => {
// console.log(count)
//})
const customInternalObservable = Observable.create(observer => {
let count = 0
setInterval(() => {
observer.next(count)
if (count == 2){
observer.complete()
}
if (count > 3){
observer.error(new Error('Count is greater 3!'))
}
count++
}, 1000)
})
this.firstObsSubscription = customInternalObservable
.pipe(
filter((data:number) => {
return data > 1
}),
map((data: number) => {
return 'Round: ' + (data+1)
})
).subscribe((count) => {
console.log(count)
}, error => {
console.log(error)
}, () => {
console.log('completed')
})
}
ngOnDestroy(){
this.firstObsSubscription.unsubscribe()
}
}
