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 { }
  • 相关阅读:
    window10使用vagrant+virtualBox搭建centos7
    吾日三思
    搭建EFK过程
    docker端口映射失效解决方法
    centos7防火墙相关命令
    docker学习
    python 读取hive数据
    shell 命令 查看本机ip
    shell 命令 修改hosts文件
    shell 命令 mkdir -p
  • 原文地址:https://www.cnblogs.com/Answer1215/p/12490379.html
Copyright © 2011-2022 走看看