Notice: file_put_contents(): Write of 16880 bytes failed with errno=28 No space left on device in /var/www/tgoop/post.php on line 50
Frontender Libs - обзор библиотек JS / CSS@sWebDev P.3096
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: |

Healing through screaming therapy Done! Now you’re the proud owner of a Telegram channel. The next step is to set up and customize your channel. Content is editable within two days of publishing “[The defendant] could not shift his criminal liability,” Hui said. During the meeting with TSE Minister Edson Fachin, Perekopsky also mentioned the TSE channel on the platform as one of the firm's key success stories. Launched as part of the company's commitments to tackle the spread of fake news in Brazil, the verified channel has attracted more than 184,000 members in less than a month.
from us


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