What are viewproviders in Angular? And what is the difference b/w providers vs viewproviders?

前端 未结 2 560
故里飘歌
故里飘歌 2020-12-23 18:43

What is viewProviders in the below code? And how it differs from providers?

class Greeter {
   greet(name:string) {
           


        
2条回答
  •  心在旅途
    2020-12-23 19:07

    1. If we want to share one instance of a service across the entirety of our application we configure it in providers on our NgModule.
    2. If we want to have one instance of a service per component, and shared with all the component’s children, we configure it on the providers property on our component decorator. Child is a view children.
    3. If we want to have one instance of a service per component, and shared with only the component’s view children and not the component’s content children, we configure it on the viewProviders property of our component decorator.

提交回复
热议问题