0

My Question id related to a previous thread answer. Angular 7 Hide bootstrap modal in typscript

The Solution provided to hide the modal in typescript code was to have the @ViewChild(ModalDirective) modal : ModalDirective access the local reference and then use method hide on that.

But according to my understanding as a beginner to Angular @ViewChild('modal') modal : ModalDirective should be used since @ViewChild takes local reference as an argument. Then why have we passed ModalDirective.

1 Answers1

0

From the docs: https://angular.io/api/core/ViewChild

The following selectors are supported.

  • Any class with the @Component or @Directive decorator

  • A template reference variable as a string (e.g. query <my-component #cmp></my-component> with @ViewChild('cmp'))

  • Any provider defined in the child component tree of the current component (e.g. @ViewChild(SomeService) someService: SomeService)
  • Any provider defined through a string token (e.g. @ViewChild('someToken') someTokenVal: any)
  • A TemplateRef (e.g. query <ng-template></ng-template> with @ViewChild(TemplateRef) template;)
Tiep Phan
  • 12,386
  • 3
  • 38
  • 41
  • what is the use case of getting child component provider in parent component. For example, Any provider defined in the child component tree of the current component (e.g. @ViewChild(SomeService) someService: SomeService) – Kavar Rushikesh Jan 16 '21 at 07:39