feat(ivy): support providers and viewProviders (#25803)
PR Close #25803
This commit is contained in:

committed by
Matias Niemelä

parent
9dc52d9d04
commit
b0476f308b
@ -102,9 +102,9 @@ export function InheritDefinitionFeature(definition: DirectiveDef<any>| Componen
|
||||
const superContentQueries = superDef.contentQueries;
|
||||
if (superContentQueries) {
|
||||
if (prevContentQueries) {
|
||||
definition.contentQueries = () => {
|
||||
superContentQueries();
|
||||
prevContentQueries();
|
||||
definition.contentQueries = (dirIndex: number) => {
|
||||
superContentQueries(dirIndex);
|
||||
prevContentQueries(dirIndex);
|
||||
};
|
||||
} else {
|
||||
definition.contentQueries = superContentQueries;
|
||||
|
45
packages/core/src/render3/features/providers_feature.ts
Normal file
45
packages/core/src/render3/features/providers_feature.ts
Normal file
@ -0,0 +1,45 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import {Provider} from '../../di/provider';
|
||||
import {providersResolver} from '../di_setup';
|
||||
import {DirectiveDef} from '../interfaces/definition';
|
||||
|
||||
/**
|
||||
* This feature resolves the providers of a directive (or component),
|
||||
* and publish them into the DI system, making it visible to others for injection.
|
||||
*
|
||||
* For example:
|
||||
* class ComponentWithProviders {
|
||||
* constructor(private greeter: GreeterDE) {}
|
||||
*
|
||||
* static ngComponentDef = defineComponent({
|
||||
* type: ComponentWithProviders,
|
||||
* selectors: [['component-with-providers']],
|
||||
* factory: () => new ComponentWithProviders(directiveInject(GreeterDE as any)),
|
||||
* consts: 1,
|
||||
* vars: 1,
|
||||
* template: function(fs: RenderFlags, ctx: ComponentWithProviders) {
|
||||
* if (fs & RenderFlags.Create) {
|
||||
* text(0);
|
||||
* }
|
||||
* if (fs & RenderFlags.Update) {
|
||||
* textBinding(0, bind(ctx.greeter.greet()));
|
||||
* }
|
||||
* },
|
||||
* features: [ProvidersFeature([GreeterDE])]
|
||||
* });
|
||||
* }
|
||||
*
|
||||
* @param definition
|
||||
*/
|
||||
export function ProvidersFeature<T>(providers: Provider[], viewProviders: Provider[] = []) {
|
||||
return (definition: DirectiveDef<T>) => {
|
||||
definition.providersResolver = (def: DirectiveDef<T>) =>
|
||||
providersResolver(def, providers, viewProviders);
|
||||
};
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import {diPublic} from '../di';
|
||||
import {DirectiveDef} from '../interfaces/definition';
|
||||
|
||||
/**
|
||||
* This feature publishes the directive (or component) into the DI system, making it visible to
|
||||
* others for injection.
|
||||
*
|
||||
* @param definition
|
||||
*/
|
||||
export function PublicFeature<T>(definition: DirectiveDef<T>) {
|
||||
definition.diPublic = diPublic;
|
||||
}
|
Reference in New Issue
Block a user