zoukankan      html  css  js  c++  java
  • [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 { }
  • 相关阅读:
    App案例分析——XBMC
    四则运算题目生成程序(基于控制台)
    第一次结对编程
    第二次作业--摩拜单车
    第0次作业
    团队编程作业1-团队展示与选题
    结对编程1-模块化
    APP案例分析
    第1次作业
    第0道作业
  • 原文地址:https://www.cnblogs.com/Answer1215/p/12490379.html
Copyright © 2011-2022 走看看