Angular2 component definition with additional configuration decoration

邮差的信 提交于 2019-12-25 14:46:51

问题


I want to pass a provider right to a component.

@NgModule({
    declarations:[
        SomeComponent.withProviders([provider1,provider2]),
        AnotherComponent.withProviders([provider1,provider2])
    ]
})
export class NestedModule{}

My question: Can I configure my components while defining them in the module like above?

More information:

The reason do I need such a thing:

  • I need to define a value provider at module level.
  • The component looks at it's parent component to find say provider1 if it doesn't have one.
  • I need to define the value provider at the SomeComponent's module level (the NestedModule).
  • The parent component belongs to another module and it has a provider with the same key but with a different value at it's module level.
  • I want to declare the value provider in a single place not to
    redefine it for each component. Any other solution is welcome.

来源:https://stackoverflow.com/questions/43581292/angular2-component-definition-with-additional-configuration-decoration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!