[Angular] Understanding the Angular Component providers property
Let's say we have App.component.ts, it use provider inside component level:
@Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] providers: [LoadingService] }) export class AppComponent implements OnInit { }
What is mean is that all the child components under App component tree, will have 'LoadService' available. But the child component must appear in Template.
<app> <course-dialog></course-dialog> </app>
In this case, if we want to use "LoadService" inside 'CouseDialog' component, we don't need to add 'providers' in 'CourseDialog' component.
But we don't have '<course-dialog>' inside template. Instead we open dialog component like:
const dialogRef = this.dialog.open(CourseDialogComponent, dialogConfig);
It open the dialog dynamicly. Then we have to use providers.
@Component({ selector: 'courses-card-list', templateUrl: './courses-card-list.component.html', styleUrls: ['./courses-card-list.component.css'], providers: [LoaderService] }) export class CoursesCardListComponent { }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2019-03-14 [Bash] Create Aliases in .bash_profile for Common Bash Commands
2019-03-14 [Algorithm] Radix Sort Algorithm
2018-03-14 [HTML 5] Styling with ARIA
2017-03-14 [Node.js] Initialize a LoopBack Node.js Project through the CLI
2017-03-14 [Angular] Pipes as providers
2017-03-14 [Angular] Create a custom pipe
2017-03-14 [Angular] Create a simple *ngFor