SWEBDEV Telegram 3096
Внедрение зависимостей в динамические компоненты

ViewContainerRef в Angular позволяет динамически создавать компоненты и внедрять в них зависимости. Сначала нужно получить доступ к ViewContainerRef через @ViewChild, затем использовать метод createComponent для создания экземпляра компонента. После создания можно передать данные через инстанс компонента.

Пример:
@Component({
selector: 'app-dynamic-host',
template: `<ng-container #container></ng-container>`,
})
export class DynamicHostComponent {
@ViewChild('container', { read: ViewContainerRef, static: true })
container!: ViewContainerRef;

loadComponent() {
const componentRef = this.container.createComponent(DynamicComponent);
componentRef.instance.data = 'Переданные данные';
}
}

@Component({
selector: 'app-dynamic-component',
template: `<p>{{ data }}</p>`,
})
export class DynamicComponent {
data!: string;
}

👉 @sWebDev
🔥41



tgoop.com/sWebDev/3096
Create:
Last Update:

Внедрение зависимостей в динамические компоненты

ViewContainerRef в Angular позволяет динамически создавать компоненты и внедрять в них зависимости. Сначала нужно получить доступ к ViewContainerRef через @ViewChild, затем использовать метод createComponent для создания экземпляра компонента. После создания можно передать данные через инстанс компонента.

Пример:

@Component({
selector: 'app-dynamic-host',
template: `<ng-container #container></ng-container>`,
})
export class DynamicHostComponent {
@ViewChild('container', { read: ViewContainerRef, static: true })
container!: ViewContainerRef;

loadComponent() {
const componentRef = this.container.createComponent(DynamicComponent);
componentRef.instance.data = 'Переданные данные';
}
}

@Component({
selector: 'app-dynamic-component',
template: `<p>{{ data }}</p>`,
})
export class DynamicComponent {
data!: string;
}

👉 @sWebDev

BY Frontender Libs - обзор библиотек JS / CSS




Share with your friend now:
tgoop.com/sWebDev/3096

View MORE
Open in Telegram


Telegram News

Date: |

The channel also called on people to turn out for illegal assemblies and listed the things that participants should bring along with them, showing prior planning was in the works for riots. The messages also incited people to hurl toxic gas bombs at police and MTR stations, he added. Click “Save” ; In the next window, choose the type of your channel. If you want your channel to be public, you need to develop a link for it. In the screenshot below, it’s ”/catmarketing.” If your selected link is unavailable, you’ll need to suggest another option. “[The defendant] could not shift his criminal liability,” Hui said. Telegram channels enable users to broadcast messages to multiple users simultaneously. Like on social media, users need to subscribe to your channel to get access to your content published by one or more administrators.
from us


Telegram Frontender Libs - обзор библиотек JS / CSS
FROM American