3. Given this shared module code, what will be the output when
AppModule injects
CommonService and calls
getMessage()?
import { Module } from '@nestjs/common';
import { CommonService } from './common.service';
@Module({
providers: [CommonService],
exports: [CommonService],
})
export class SharedModule {}
// CommonService
export class CommonService {
getMessage() {
return 'Hello from SharedModule';
}
}
// AppModule
import { Module } from '@nestjs/common';
import { SharedModule } from './shared.module';
@Module({
imports: [SharedModule],
})
export class AppModule {
constructor(private commonService: CommonService) {}
printMessage() {
console.log(this.commonService.getMessage());
}
}