Valentines Day

NgModule

Service

Component

Module

Service

Controller



import { NgModule } from '@angular/core';

import { OtherModule } from './other.module';
import { AppComponent } from './app.component';
import { AppService } from './app.service';

@NgModule({
  imports:      [ OtherModule ],
  declarations: [ AppComponent ],
  providers:    [ AppService ]
})
export class AppModule { }


import { Module } from '@nestjs/common';

import { OtherModule } from './other.module';
import { AppComponent } from './app.component';
import { AppService } from './app.service';

@Module({
  imports:      [ OtherModule ],
  declarations: [ AppComponent ],
  providers:    [ AppService ]
})
export class AppModule { }


import { Module } from '@nestjs/common';

import { OtherModule } from './other.module';
import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
  imports:      [ OtherModule ],
  controllers:  [ AppController ],
  providers:    [ AppService ]
})
export class AppModule { }


import { Module } from '@nestjs/common';

import { OtherModule } from './other.module';
import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
  imports:      [ OtherModule ],
  controllers:  [ AppController ],
  providers:    [ AppService ]
})
export class AppModule { }

It's the same



import { Get, Controller } from '@nestjs/common';
import { CatService } from './cat.service';

@Controller()
export class CatController {

  constructor(private readonly catService: CatService) {}





  findAll(): Cat[] {
    return this.catService.findAll();
  }
}

Dependency Injection like in Angular



import { Get, Controller } from '@nestjs/common';
import { CatService } from './cat.service';

@Controller("cats")
export class CatController {

  constructor(private readonly catService: CatService) {}





  findAll(): Cat[] {
    return this.catService.findAll();
  }
}


import { Get, Controller } from '@nestjs/common';
import { CatService } from './cat.service';

@Controller("cats")
export class CatController {

  constructor(private readonly catService: CatService) {}




  @Get()
  findAll(): Cat[] {
    return this.catService.findAll();
  }
}


import { Get, Controller } from '@nestjs/common';
import { CatService } from './cat.service';

@Controller("cats")
export class CatController {

  constructor(private readonly catService: CatService) {}




  @Get()
  @Header('Content-Type', 'application/json')
  findAll(): Cat[] {
    return this.catService.findAll();
  }
}


import { Get, Controller } from '@nestjs/common';
import { CatService } from './cat.service';

@Controller("cats")
export class CatController {

  constructor(private readonly catService: CatService) {}




  @Get()
  @Header('Content-Type', 'application/json')
  async findAll(): Promise<Cat[]> {
    return this.catService.findAll();
  }
}


import { Get, Controller } from '@nestjs/common';
import { CatService } from './cat.service';

@Controller("cats")
export class CatController {

  constructor(private readonly catService: CatService) {}




  @Get()
  @Header('Content-Type', 'application/json')
  findAll(): Observable<Cat[]> {
    return this.catService.findAll();
  }
}


import { Get, Post, Controller } from '@nestjs/common';
import { CatService } from './cat.service';

@Controller("cats")
export class CatController {

  constructor(private readonly catService: CatService) {}


  @Post()
  create(@Body() createCatDto): Observable<Cat> {
    return this.catService.createCat(createCatDto);
  }

  @Get()
  @Header('Content-Type', 'application/json')
  findAll(): Observable<Cat[]> {
    return this.catService.findAll();
  }
}


import { Get, Post, Controller } from '@nestjs/common';
import { CatService } from './cat.service';

@Controller("cats")
export class CatController {

  constructor(private readonly catService: CatService) {}


  @Post()
  @HttpCode(201)
  create(@Body() createCatDto): Observable<Cat> {
    return this.catService.createCat(createCatDto);
  }

  @Get()
  @Header('Content-Type', 'application/json')
  findAll(): Observable<Cat[]> {
    return this.catService.findAll();
  }
}


import { Get, Post, Put, Controller } from '@nestjs/common';
import { CatService } from './cat.service';

@Controller("cats")
export class CatController {

  constructor(private readonly catService: CatService) {}


  @Post()
  @HttpCode(204)
  create(@Body() createCatDto): Observable<Cat> {
    return this.catService.createCat(createCatDto);
  }

  @Put(":id")
  update(
    @Param('id') id,
    @Body() updateCatDto
  ): Observable<Cat[]> {
    return this.catService.updateCat(id, updateCatDto);
  }

  @Get()
  @Header('Content-Type', 'application/json')
  getAll(): Observable<Cat[]> {
    return this.catService.findAll();
  }
}


import { Injectable } from '@nestjs/common';
import { Cat } from './interfaces/cat.interface';

@Injectable()
export class CatService {
  private readonly cats: Cat[] = [];

  create(cat: Cat) {
    this.cats.push(cat);
  }

  findAll(): Cat[] {
    return this.cats;
  }
}

collection of runtime libraries, linters, and code generators

Monorepo-style development

Angular CLI as graphical user interface

And much more!

Coding time

Let's Have some fun!

Who has a date tonight ?

Thank you!

Mitko Tschimev

@MTschimev

mitko@dev-thought.cool

message

who fell in 🥰 ?

Angular and NestJS

By Mitko Tschimev

Angular and NestJS

  • 962