模块
声明共享
在app-modules中 exports导出 声明服务为共享
@Module({
controllers: [UserController],
providers: [UserService],
exports:[UserService]
})
在controller中引用:
import { UserService } from './user/user.service';
@Controller('')
export class AppController {
constructor(private readonly appService: AppService,private readonly userService: UserService) {}
@Get('')
getHello(): string {
return this.userService.findAll();
}
全局模块
声明一个module
import { Global, Module } from "@nestjs/common";
@Global()
@Module({
providers: [
{
provide: "Config",
useValue: {baseUrl:"api"}
}
]
})
export class ConfigModule{
}
在app.module中注册
标签:providers,app,module,Module,模块,UserService From: https://www.cnblogs.com/mykai/p/17755841.html