update injector value on record input change

pull/12956/head
muhammedaltug 3 years ago
parent 8b104856c5
commit fc4e75c30f

@ -8,10 +8,7 @@
<ng-container *abpPermission="action.permission">
<ng-container *ngIf="action.component as component; else button">
<ng-container
*ngComponentOutlet="
component;
injector: action | createInjector: data:getInjected
"
*ngComponentOutlet="component; injector: record | createInjector: action:this"
></ng-container>
</ng-container>

@ -16,10 +16,11 @@ import { AbstractActionsComponent } from '../abstract-actions/abstract-actions.c
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class PageToolbarComponent<R = any> extends AbstractActionsComponent<ToolbarActionList<R>> {
getData = () => this.data;
readonly trackByFn: TrackByFunction<ToolbarComponent<R>> = (_, item) =>
item.action || item.component;
constructor(private readonly injector: Injector) {
constructor(public readonly injector: Injector) {
super(injector);
}
}

@ -1,28 +1,27 @@
import { InjectFlags, InjectionToken, Injector, Pipe, PipeTransform, Type } from '@angular/core';
import { InferredData, ToolbarComponent } from '../models/toolbar-actions';
import {
EXTENSIONS_ACTION_CALLBACK,
EXTENSIONS_ACTION_DATA,
} from '@abp/ng.theme.shared/extensions';
import { ReadonlyActionData } from '../models/actions';
import { ToolbarComponent } from '../models/toolbar-actions';
import { EXTENSIONS_ACTION_CALLBACK, EXTENSIONS_ACTION_DATA } from '../tokens/extensions.token';
import { PageToolbarComponent } from '../components/page-toolbar/page-toolbar.component';
@Pipe({
name: 'createInjector',
})
export class CreateInjectorPipe<R> implements PipeTransform {
constructor(private injector: Injector) {}
public transform(
_: any,
action: ToolbarComponent<R>,
componentData: ReadonlyActionData<R>,
getInjectedFn: InferredData<R>['getInjected'],
context: PageToolbarComponent<R>,
): Injector {
const get = <T>(token: Type<T> | InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags) => {
const componentData = context.getData();
return token === EXTENSIONS_ACTION_DATA
? componentData
: token === EXTENSIONS_ACTION_CALLBACK
? (data = componentData) => action.action(data)
: getInjectedFn.call(this.injector, token, notFoundValue, flags);
? data => {
data = data ?? context.getData();
return action.action(data);
}
: context.getInjected.call(context.injector, token, notFoundValue, flags);
};
return { get };
}

Loading…
Cancel
Save