{"id":330057,"date":"2022-02-24T09:00:38","date_gmt":"2022-02-24T09:00:38","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=330057"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=330057","title":{"rendered":"<span>\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0449\u0435: \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 Angular 13<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0411\u044b\u0432\u0430\u044e\u0442 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0443\u043b\u0442\u0438\u043f \u0438\u043b\u0438 \u0431\u0430\u043d\u043d\u0435\u0440. \u0412 \u0442\u0430\u043a\u0438\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 Angular, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043c\u0435\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435 \u0438 \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u0442\u044c \u0438\u0445. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u043c createComponent \u0443 <a href=\"https:\/\/angular.io\/api\/core\/ViewContainerRef#viewcontainerref\">ViewContainerRef<\/a>.<\/p>\n<p>\u041d\u043e \u0441 13 \u0432\u0435\u0440\u0441\u0438\u0435\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 API \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0441\u044f.\u00a0\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u043e\u0434\u0435\u043b\u044e\u0441\u044c \u0442\u0435\u043c, \u043a\u0430\u043a \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430.<\/p>\n<p><em>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u044d\u0442\u043e\u043c, \u0445\u043e\u0447\u0443 \u043f\u043e\u0437\u0434\u0440\u0430\u0432\u0438\u0442\u044c \u0441 \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043f\u0435\u0440\u0435\u0435\u0437\u0434\u043e\u043c \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 \u043d\u0430 Ivy, \u043d\u043e\u0432\u044b\u0439 \u0434\u0432\u0438\u0436\u043e\u043a \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433\u0430 Angular. \u041d\u0430\u043a\u043e\u043d\u0435\u0446-\u0442\u043e \u043c\u044b \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0449\u0430\u043b\u0438\u0441\u044c \u0441 View Engine, \u0438 \u0442\u0435\u043f\u0435\u0440\u044c Ivy \u043f\u043e\u043a\u0430\u0436\u0435\u0442 \u0441\u0435\u0431\u044f \u0432 \u043f\u043e\u043b\u043d\u043e\u0439 \u043c\u0435\u0440\u0435<\/em>! <\/p>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044f\u0441\u044c \u043a \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c: \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c DynamicComponent, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c: <\/p>\n<p><strong>dynamic.component.ts<\/strong><\/p>\n<pre><code>import {Component} from '@angular\/core';  @Component({   selector: 'app-dynamic',   template: `     &lt;div>&lt;img       src='https:\/\/images.pexels.com\/photos\/7294069\/pexels-photo-7294069.jpeg?auto=compress&amp;cs=tinysrgb&amp;h=750&amp;w=350'       alt='image'>     &lt;\/div>`,   styles: [`     :host {       text-align: center;     }`   ] }) export class DynamicComponent { } <\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0431\u0443\u0434\u0435\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0432 AppComponent \u043f\u0440\u0438 \u043a\u043b\u0438\u043a\u0435 \u043d\u0430 \u00ab<strong>show-btn<\/strong>\u00bb \u0438 \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u043f\u043e \u043a\u043d\u043e\u043f\u043a\u0435 \u00ab<strong>remove-btn<\/strong>\u00bb \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0434\u043b\u044f \u043d\u0438\u0445 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438: <code>showDynamicComponent<\/code> \u0438 <code>removeDynamicComponent<\/code> \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e.<\/p>\n<p><strong>app.component.html<\/strong><\/p>\n<pre><code>&lt;div class=\"buttons-container\">   &lt;button class=\"show-btn\" (click)=\"showDynamicComponent()\">Show component&lt;\/button>   &lt;button class=\"remove-btn\" (click)=\"removeDynamicComponent()\">     Remove component   &lt;\/button> &lt;\/div> &lt;ng-template #dynamic>&lt;\/ng-template><\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 <code>&lt;ng-template #dynamic>&lt;\/ng-template><\/code><em> \u2014 \u044d\u0442\u043e <\/em>\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0434\u043b\u044f <code>DynamicComponent<\/code>. \u0418\u043c\u0435\u043d\u043d\u043e \u0437\u0434\u0435\u0441\u044c \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c\u0441\u044f \u043d\u0430\u0448 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442.<\/p>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441\u0430\u043c\u043e\u0435 \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u2014 \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0442\u0430\u043a\u0438\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c:<\/p>\n<h2>\u041a\u0430\u043a \u0431\u044b\u043b\u043e \u0434\u043e Angular 13<\/h2>\n<p>1) \u0421 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u043c \u043c\u044b \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438, \u0442\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u0439\u043c\u0435\u043c\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u043e\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430. \u0421\u043f\u0435\u0440\u0432\u0430 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a <code>showDynamicComponent<\/code>.<\/p>\n<p><strong>app.component.ts<\/strong><\/p>\n<pre><code>import {   Component,   ComponentFactoryResolver,   ComponentRef,   OnDestroy,   ViewChild,   ViewContainerRef, } from '@angular\/core'; import { DynamicComponent } from '.\/dynamic.component';  @Component({   selector: 'my-app',   templateUrl: '.\/app.component.html',   styleUrls: ['.\/app.component.css'], }) export class AppComponent implements OnDestroy {   @ViewChild('dynamic', { read: ViewContainerRef })   private viewRef: ViewContainerRef;    private componentRef: ComponentRef&lt;DynamicComponent>;    constructor(     private readonly componentFactoryResolver: ComponentFactoryResolver   ) {}    showDynamicComponent(): void {     this.viewRef.clear(); \/\/ destroys all views in container     const componentFactory =       this.componentFactoryResolver.resolveComponentFactory(DynamicComponent);     this.componentRef = this.viewRef.createComponent(componentFactory);   } }<\/code><\/pre>\n<p>\u0427\u0442\u043e \u0437\u0430 <a href=\"https:\/\/angular.io\/api\/core\/ComponentFactory\"><em>componentFactory<\/em><\/a> \u043d\u0430 28 \u0441\u0442\u0440\u043e\u043a\u0435? \u042d\u0442\u043e \u0444\u0430\u0431\u0440\u0438\u043a\u0430 \u043d\u0430\u0448\u0435\u0433\u043e \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u0430\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/angular.io\/api\/core\/ComponentFactoryResolver\"><em>ComponentFactoryResolver<\/em><\/a>. <\/p>\n<p>\u0410 <code>ComponentFactoryResolver<\/code><em> \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435\u043c, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u043e \u043a\u043b\u044e\u0447\u0443 <\/em><code>DynamicComponent<\/code><em> \u043d\u0430\u0439\u0434\u0435\u0442 \u0438 \u0432\u0435\u0440\u043d\u0435\u0442 \u0444\u0430\u0431\u0440\u0438\u043a\u0443, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0443\u044e \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 <\/em><code>DynamicComponent<\/code><em>.<\/em><\/p>\n<p>\u041d\u0430 30 \u0441\u0442\u0440\u043e\u043a\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043d\u0430\u0448 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u2014 <code>this.componentRef<\/code><em>. <\/em>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0435\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 <code>DynamicComponent<\/code> \u0432 \u043c\u0435\u0442\u043e\u0434 <code>createComponent<\/code> \u0443 <a href=\"https:\/\/angular.io\/api\/core\/ViewContainerRef\"><em>this.viewRef<\/em><\/a> <em>(\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430).<\/em><\/p>\n<p>\u0421\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430 \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430:<\/p>\n<pre><code>abstract createComponent&lt;C>( componentFactory: ComponentFactory&lt;C>, index?: number, injector?: Injector, projectableNodes?: any[][], ngModuleRef?: NgModuleRef&lt;any> ): ComponentRef&lt;C><\/code><\/pre>\n<p>\u041f\u043e\u043c\u0438\u043c\u043e \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b, \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0439 \u0432 <a href=\"https:\/\/angular.io\/api\/core\/ViewContainerRef#createcomponent\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>.<\/p>\n<p>2) \u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043c\u044b \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438 \u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u043a \u0435\u0433\u043e \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044e: \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a <code>removeDynamicComponent<\/code><em> <\/em>\u0434\u043b\u044f \u043a\u043d\u043e\u043f\u043a\u0438 \u00ab<em>remove-btn<\/em>\u00bb.<\/p>\n<p><strong>app.component.ts:<\/strong><\/p>\n<pre><code>import {   Component,   ComponentFactoryResolver,   ComponentRef,   ViewChild,   ViewContainerRef, } from '@angular\/core'; import { DynamicComponent } from '.\/dynamic.component';  @Component({   selector: 'my-app',   templateUrl: '.\/app.component.html',   styleUrls: ['.\/app.component.css'], }) export class AppComponent {   @ViewChild('dynamic', { read: ViewContainerRef })   private viewRef: ViewContainerRef;    private componentRef: ComponentRef&lt;DynamicComponent>;    constructor(     private readonly componentFactoryResolver: ComponentFactoryResolver   ) {}    showDynamicComponent(): void {     this.viewRef.clear(); \/\/ destroys all views in container     const componentFactory =       this.componentFactoryResolver.resolveComponentFactory(DynamicComponent);     this.componentRef = this.viewRef.createComponent(componentFactory);   }    removeDynamicComponent(): void {     this.viewRef.clear(); \/\/ destroys all views in container   } } <\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0447\u0438\u0449\u0430\u0435\u043c \u043d\u0430\u0448 view-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u043e\u0442 \u0432\u0441\u0435\u0445 <a href=\"https:\/\/angular.io\/guide\/glossary#view\">\u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0439<\/a>, \u0438 <code>DynamicComponent<\/code> \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u0435\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c\u0441\u044f.<\/p>\n<p><strong>\u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 app.component.ts<\/strong><\/p>\n<pre><code>import {   Component,   ComponentFactoryResolver,   ComponentRef,   ViewChild,   ViewContainerRef, } from '@angular\/core'; import { DynamicComponent } from '.\/dynamic.component';  @Component({   selector: 'my-app',   templateUrl: '.\/app.component.html',   styleUrls: ['.\/app.component.css'], }) export class AppComponent {   @ViewChild('dynamic', { read: ViewContainerRef })   private viewRef: ViewContainerRef;    private componentRef: ComponentRef&lt;DynamicComponent>;    constructor(     private readonly componentFactoryResolver: ComponentFactoryResolver   ) {}    showDynamicComponent(): void {     this.viewRef.clear();     const componentFactory =       this.componentFactoryResolver.resolveComponentFactory(DynamicComponent);     this.componentRef = this.viewRef.createComponent(componentFactory);   }    removeDynamicComponent(): void {     this.viewRef.clear();   } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043d\u0430\u0448 \u043a\u043e\u0434:<\/p>\n<figure class=\"bordered full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/3bc\/580\/fa1\/3bc580fa124aee582cf024bb72daaa8b.gif\" alt=\"    \" title=\"    \" width=\"600\" height=\"606\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3bc\/580\/fa1\/3bc580fa124aee582cf024bb72daaa8b.gif\"\/><figcaption>    <\/figcaption><\/figure>\n<p>\u0412\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0438\u0434\u0435\u043c \u0434\u0430\u043b\u044c\u0448\u0435 \ud83d\ude42<\/p>\n<h2>\u0427\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c \u0432 13 \u0432\u0435\u0440\u0441\u0438\u0438 Angular<\/h2>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u043b\u043e\u0441\u044c API \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 (\u043d\u0430\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u0431\u043e\u0442\u0438\u0442\u044c\u0441\u044f \u043e \u0435\u0433\u043e \u0444\u0430\u0431\u0440\u0438\u043a\u0435), \u0430 \u0432 13.2 \u0432\u0435\u0440\u0441\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u044b <code>ComponentFactory<\/code> \u0438 <code>ComponentFactoryResolver<\/code> \u0443\u0441\u0442\u0430\u0440\u0435\u043b\u0438.<\/p>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043d\u043e\u0432\u0443\u044e \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443 \u043c\u0435\u0442\u043e\u0434\u0430:<\/p>\n<pre><code>abstract createComponent&lt;C>(   componentType: Type&lt;C>,   options?: {     index?: number;     injector?: Injector;      ngModuleRef?: NgModuleRef&lt;unknown>;     projectableNodes?: Node[][]; } ): ComponentRef&lt;C><\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0442\u0438\u043f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 <code>DynamicComponent<\/code><em> <\/em>\u0432 \u043c\u0435\u0442\u043e\u0434 <code>createComponent<\/code>, \u0430 \u0441 \u0444\u0430\u0431\u0440\u0438\u043a\u043e\u0439 Angular \u0441\u0430\u043c \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u0442\u0441\u044f.<\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a <code>showDynamicComponent<\/code>:<\/p>\n<p><strong>app.component.ts\u00a0\u00a0<\/strong><\/p>\n<pre><code>import { Component, ViewChild, ViewContainerRef } from '@angular\/core'; import { DynamicComponent } from '.\/dynamic.component';  @Component({   selector: 'my-app',   templateUrl: '.\/app.component.html',   styleUrls: ['.\/app.component.css'], }) export class AppComponent {   @ViewChild('dynamic', { read: ViewContainerRef })   private viewRef: ViewContainerRef;   private componentRef: ComponentRef&lt;DynamicComponent>;    showDynamicComponent(): void {     this.viewRef.clear();     this.componentRef = this.viewRef.createComponent(DynamicComponent); \/\/ \u0442\u0435\u043f\u0435\u0440\u044c \u0442\u0430\u043a   }    removeDynamicComponent(): void {     this.viewRef.clear();   } }<\/code><\/pre>\n<p>\u0421\u0442\u043e\u0438\u0442 \u0443\u0442\u043e\u0447\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u0445\u043e\u0442\u044c \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 <code>createComponent<\/code> \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0430\u0441\u044c, \u043c\u044b \u0432\u0441\u0435 \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c index, <a href=\"https:\/\/angular.io\/api\/core\/Injector\">injector<\/a>, <a href=\"https:\/\/angular.io\/api\/core\/NgModuleRef\">ngModuleRef<\/a> \u0438 projectableNodes, \u043d\u043e \u0443\u0436\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c.<\/p>\n<p>\u0410 \u0437\u0430 \u0441\u0447\u0435\u0442 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e <code>createComponent<\/code> \u0432\u0441\u0435 \u0442\u0430\u043a \u0436\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>ComponentRe<\/code><em>f<\/em>, \u043d\u0430\u043c \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043c\u0435\u043d\u044f\u0442\u044c \u043a\u043e\u0434 \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435 \u043d\u0430 \u043d\u043e\u0432\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430.<\/p>\n<h2>\u0412\u044b\u0432\u043e\u0434<\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0443\u0437\u043d\u0430\u043b\u0438, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0432 13 \u0432\u0435\u0440\u0441\u0438\u0438 Angular \u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u043e\u0442\u043b\u0438\u0447\u0438\u044f \u043e\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0441\u0442\u0430\u043b\u043e \u043f\u0440\u043e\u0449\u0435:<\/p>\n<ul>\n<li>\n<p>\u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u0435\u0441\u043f\u043e\u043a\u043e\u0438\u0442\u044c\u0441\u044f \u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0444\u0430\u0431\u0440\u0438\u043a\u0438<\/p>\n<\/li>\n<li>\n<p>\u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0438\u043d\u0436\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438<\/p>\n<\/li>\n<li>\n<p>\u0441\u0445\u043e\u0436\u0430\u044f \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430<\/p>\n<\/li>\n<\/ul>\n<p>Angular \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043b\u0443\u0447\u0448\u0435 \u0438 \u043b\u0443\u0447\u0448\u0435 \ud83d\ude42<\/p>\n<p>\u0411\u044b\u043b\u043e (Angular &lt;= 12):<\/p>\n<pre><code>export class AppComponent implements {   @ViewChild('dynamic', { read: ViewContainerRef })   private viewRef: ViewContainerRef;    private componentRef: ComponentRef&lt;DynamicComponent>;    constructor(     private readonly componentFactoryResolver: ComponentFactoryResolver   ) {}    showDynamicComponent(): void {     this.viewRef.clear();     const componentFactory =       this.componentFactoryResolver.resolveComponentFactory(DynamicComponent);     this.componentRef = this.viewRef.createComponent(componentFactory);   }    removeDynamicComponent(): void {     this.viewRef.clear();   } }<\/code><\/pre>\n<p>\u0421\u0442\u0430\u043b\u043e (Angular 13):<\/p>\n<pre><code>export class AppComponent {   @ViewChild('dynamic', { read: ViewContainerRef })   private viewRef: ViewContainerRef;    showDynamicComponent(): void {     this.viewRef.clear();     this.viewRef.createComponent(DynamicComponent);   }    removeDynamicComponent(): void {     this.viewRef.clear();   } }<\/code><\/pre>\n<p><a href=\"https:\/\/stackblitz.com\/edit\/angular-yqfxxn\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0441\u0442\u0430\u0440\u044b\u0439 \u043a\u043e\u0434<\/a>.<br \/><a href=\"https:\/\/stackblitz.com\/edit\/angular-mcbbub\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043d\u043e\u0432\u044b\u0439 \u043a\u043e\u0434<\/a>.<\/p>\n<p><strong>\u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438<\/strong><\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/stackblogger.com\/dynamic-components-angular\/\">https:\/\/stackblogger.com\/dynamic-components-angular\/<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/angular.io\/guide\/dynamic-component-loader\"><u>https:\/\/angular.io\/guide\/dynamic-component-loader<\/u><\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/betterprogramming.pub\/angular-13-features-ef528a9ae16f\"><u>https:\/\/betterprogramming.pub\/angular-13-features-ef528a9ae16f<\/u><\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/indepth.dev\/posts\/1054\/here-is-what-you-need-to-know-about-dynamic-components-in-angular\">https:\/\/indepth.dev\/posts\/1054\/here-is-what-you-need-to-know-about-dynamic-components-in-angular<\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/skyeng\/blog\/652855\/\"> https:\/\/habr.com\/ru\/company\/skyeng\/blog\/652855\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0411\u044b\u0432\u0430\u044e\u0442 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0443\u043b\u0442\u0438\u043f \u0438\u043b\u0438 \u0431\u0430\u043d\u043d\u0435\u0440. \u0412 \u0442\u0430\u043a\u0438\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 Angular, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043c\u0435\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435 \u0438 \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u0442\u044c \u0438\u0445. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u043c createComponent \u0443 <a href=\"https:\/\/angular.io\/api\/core\/ViewContainerRef#viewcontainerref\">ViewContainerRef<\/a>.<\/p>\n<p>\u041d\u043e \u0441 13 \u0432\u0435\u0440\u0441\u0438\u0435\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 API \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0441\u044f.\u00a0\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u043e\u0434\u0435\u043b\u044e\u0441\u044c \u0442\u0435\u043c, \u043a\u0430\u043a \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430.<\/p>\n<p><em>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u044d\u0442\u043e\u043c, \u0445\u043e\u0447\u0443 \u043f\u043e\u0437\u0434\u0440\u0430\u0432\u0438\u0442\u044c \u0441 \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043f\u0435\u0440\u0435\u0435\u0437\u0434\u043e\u043c \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 \u043d\u0430 Ivy, \u043d\u043e\u0432\u044b\u0439 \u0434\u0432\u0438\u0436\u043e\u043a \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433\u0430 Angular. \u041d\u0430\u043a\u043e\u043d\u0435\u0446-\u0442\u043e \u043c\u044b \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0449\u0430\u043b\u0438\u0441\u044c \u0441 View Engine, \u0438 \u0442\u0435\u043f\u0435\u0440\u044c Ivy \u043f\u043e\u043a\u0430\u0436\u0435\u0442 \u0441\u0435\u0431\u044f \u0432 \u043f\u043e\u043b\u043d\u043e\u0439 \u043c\u0435\u0440\u0435<\/em>! <\/p>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044f\u0441\u044c \u043a \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c: \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c DynamicComponent, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c: <\/p>\n<p><strong>dynamic.component.ts<\/strong><\/p>\n<pre><code>import {Component} from '@angular\/core';  @Component({   selector: 'app-dynamic',   template: `     &lt;div>&lt;img       src='https:\/\/images.pexels.com\/photos\/7294069\/pexels-photo-7294069.jpeg?auto=compress&amp;cs=tinysrgb&amp;h=750&amp;w=350'       alt='image'>     &lt;\/div>`,   styles: [`     :host {       text-align: center;     }`   ] }) export class DynamicComponent { } <\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0431\u0443\u0434\u0435\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0432 AppComponent \u043f\u0440\u0438 \u043a\u043b\u0438\u043a\u0435 \u043d\u0430 \u00ab<strong>show-btn<\/strong>\u00bb \u0438 \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u043f\u043e \u043a\u043d\u043e\u043f\u043a\u0435 \u00ab<strong>remove-btn<\/strong>\u00bb \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0434\u043b\u044f \u043d\u0438\u0445 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438: <code>showDynamicComponent<\/code> \u0438 <code>removeDynamicComponent<\/code> \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e.<\/p>\n<p><strong>app.component.html<\/strong><\/p>\n<pre><code>&lt;div class=\"buttons-container\">   &lt;button class=\"show-btn\" (click)=\"showDynamicComponent()\">Show component&lt;\/button>   &lt;button class=\"remove-btn\" (click)=\"removeDynamicComponent()\">     Remove component   &lt;\/button> &lt;\/div> &lt;ng-template #dynamic>&lt;\/ng-template><\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 <code>&lt;ng-template #dynamic>&lt;\/ng-template><\/code><em> \u2014 \u044d\u0442\u043e <\/em>\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0434\u043b\u044f <code>DynamicComponent<\/code>. \u0418\u043c\u0435\u043d\u043d\u043e \u0437\u0434\u0435\u0441\u044c \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c\u0441\u044f \u043d\u0430\u0448 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442.<\/p>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441\u0430\u043c\u043e\u0435 \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u2014 \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0442\u0430\u043a\u0438\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c:<\/p>\n<h2>\u041a\u0430\u043a \u0431\u044b\u043b\u043e \u0434\u043e Angular 13<\/h2>\n<p>1) \u0421 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u043c \u043c\u044b \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438, \u0442\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u0439\u043c\u0435\u043c\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u043e\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430. \u0421\u043f\u0435\u0440\u0432\u0430 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a <code>showDynamicComponent<\/code>.<\/p>\n<p><strong>app.component.ts<\/strong><\/p>\n<pre><code>import {   Component,   ComponentFactoryResolver,   ComponentRef,   OnDestroy,   ViewChild,   ViewContainerRef, } from '@angular\/core'; import { DynamicComponent } from '.\/dynamic.component';  @Component({   selector: 'my-app',   templateUrl: '.\/app.component.html',   styleUrls: ['.\/app.component.css'], }) export class AppComponent implements OnDestroy {   @ViewChild('dynamic', { read: ViewContainerRef })   private viewRef: ViewContainerRef;    private componentRef: ComponentRef&lt;DynamicComponent>;    constructor(     private readonly componentFactoryResolver: ComponentFactoryResolver   ) {}    showDynamicComponent(): void {     this.viewRef.clear(); \/\/ destroys all views in container     const componentFactory =       this.componentFactoryResolver.resolveComponentFactory(DynamicComponent);     this.componentRef = this.viewRef.createComponent(componentFactory);   } }<\/code><\/pre>\n<p>\u0427\u0442\u043e \u0437\u0430 <a href=\"https:\/\/angular.io\/api\/core\/ComponentFactory\"><em>componentFactory<\/em><\/a> \u043d\u0430 28 \u0441\u0442\u0440\u043e\u043a\u0435? \u042d\u0442\u043e \u0444\u0430\u0431\u0440\u0438\u043a\u0430 \u043d\u0430\u0448\u0435\u0433\u043e \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u0430\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/angular.io\/api\/core\/ComponentFactoryResolver\"><em>ComponentFactoryResolver<\/em><\/a>. <\/p>\n<p>\u0410 <code>ComponentFactoryResolver<\/code><em> \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435\u043c, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u043e \u043a\u043b\u044e\u0447\u0443 <\/em><code>DynamicComponent<\/code><em> \u043d\u0430\u0439\u0434\u0435\u0442 \u0438 \u0432\u0435\u0440\u043d\u0435\u0442 \u0444\u0430\u0431\u0440\u0438\u043a\u0443, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0443\u044e \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 <\/em><code>DynamicComponent<\/code><em>.<\/em><\/p>\n<p>\u041d\u0430 30 \u0441\u0442\u0440\u043e\u043a\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043d\u0430\u0448 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u2014 <code>this.componentRef<\/code><em>. <\/em>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0435\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 <code>DynamicComponent<\/code> \u0432 \u043c\u0435\u0442\u043e\u0434 <code>createComponent<\/code> \u0443 <a href=\"https:\/\/angular.io\/api\/core\/ViewContainerRef\"><em>this.viewRef<\/em><\/a> <em>(\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430).<\/em><\/p>\n<p>\u0421\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430 \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430:<\/p>\n<pre><code>abstract createComponent&lt;C>( componentFactory: ComponentFactory&lt;C>, index?: number, injector?: Injector, projectableNodes?: any[][], ngModuleRef?: NgModuleRef&lt;any> ): ComponentRef&lt;C><\/code><\/pre>\n<p>\u041f\u043e\u043c\u0438\u043c\u043e \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b, \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0439 \u0432 <a href=\"https:\/\/angular.io\/api\/core\/ViewContainerRef#createcomponent\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>.<\/p>\n<p>2) \u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043c\u044b \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438 \u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u043a \u0435\u0433\u043e \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044e: \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a <code>removeDynamicComponent<\/code><em> <\/em>\u0434\u043b\u044f \u043a\u043d\u043e\u043f\u043a\u0438 \u00ab<em>remove-btn<\/em>\u00bb.<\/p>\n<p><strong>app.component.ts:<\/strong><\/p>\n<pre><code>import {   Component,   ComponentFactoryResolver,   ComponentRef,   ViewChild,   ViewContainerRef, } from '@angular\/core'; import { DynamicComponent } from '.\/dynamic.component';  @Component({   selector: 'my-app',   templateUrl: '.\/app.component.html',   styleUrls: ['.\/app.component.css'], }) export class AppComponent {   @ViewChild('dynamic', { read: ViewContainerRef })   private viewRef: ViewContainerRef;    private componentRef: ComponentRef&lt;DynamicComponent>;    constructor(     private readonly componentFactoryResolver: ComponentFactoryResolver   ) {}    showDynamicComponent(): void {     this.viewRef.clear(); \/\/ destroys all views in container     const componentFactory =       this.componentFactoryResolver.resolveComponentFactory(DynamicComponent);     this.componentRef = this.viewRef.createComponent(componentFactory);   }    removeDynamicComponent(): void {     this.viewRef.clear(); \/\/ destroys all views in container   } } <\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0447\u0438\u0449\u0430\u0435\u043c \u043d\u0430\u0448 view-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u043e\u0442 \u0432\u0441\u0435\u0445 <a href=\"https:\/\/angular.io\/guide\/glossary#view\">\u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0439<\/a>, \u0438 <code>DynamicComponent<\/code> \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u0435\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c\u0441\u044f.<\/p>\n<p><strong>\u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 app.component.ts<\/strong><\/p>\n<pre><code>import {   Component,   ComponentFactoryResolver,   ComponentRef,   ViewChild,   ViewContainerRef, } from '@angular\/core'; import { DynamicComponent } from '.\/dynamic.component';  @Component({   selector: 'my-app',   templateUrl: '.\/app.component.html',   styleUrls: ['.\/app.component.css'], }) export class AppComponent {   @ViewChild('dynamic', { read: ViewContainerRef })   private viewRef: ViewContainerRef;    private componentRef: ComponentRef&lt;DynamicComponent>;    constructor(     private readonly componentFactoryResolver: ComponentFactoryResolver   ) {}    showDynamicComponent(): void {     this.viewRef.clear();     const componentFactory =       this.componentFactoryResolver.resolveComponentFactory(DynamicComponent);     this.componentRef = this.viewRef.createComponent(componentFactory);   }    removeDynamicComponent(): void {     this.viewRef.clear();   } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043d\u0430\u0448 \u043a\u043e\u0434:<\/p>\n<figure class=\"bordered full-width\"><figcaption>    <\/figcaption><\/figure>\n<p>\u0412\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0438\u0434\u0435\u043c \u0434\u0430\u043b\u044c\u0448\u0435 \ud83d\ude42<\/p>\n<h2>\u0427\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c \u0432 13 \u0432\u0435\u0440\u0441\u0438\u0438 Angular<\/h2>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u043b\u043e\u0441\u044c API \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 (\u043d\u0430\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u0431\u043e\u0442\u0438\u0442\u044c\u0441\u044f \u043e \u0435\u0433\u043e \u0444\u0430\u0431\u0440\u0438\u043a\u0435), \u0430 \u0432 13.2 \u0432\u0435\u0440\u0441\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u044b <code>ComponentFactory<\/code> \u0438 <code>ComponentFactoryResolver<\/code> \u0443\u0441\u0442\u0430\u0440\u0435\u043b\u0438.<\/p>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043d\u043e\u0432\u0443\u044e \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443 \u043c\u0435\u0442\u043e\u0434\u0430:<\/p>\n<pre><code>abstract createComponent&lt;C>(   componentType: Type&lt;C>,   options?: {     index?: number;     injector?: Injector;      ngModuleRef?: NgModuleRef&lt;unknown>;     projectableNodes?: Node[][]; } ): ComponentRef&lt;C><\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0442\u0438\u043f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 <code>DynamicComponent<\/code><em> <\/em>\u0432 \u043c\u0435\u0442\u043e\u0434 <code>createComponent<\/code>, \u0430 \u0441 \u0444\u0430\u0431\u0440\u0438\u043a\u043e\u0439 Angular \u0441\u0430\u043c \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u0442\u0441\u044f.<\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a <code>showDynamicComponent<\/code>:<\/p>\n<p><strong>app.component.ts\u00a0\u00a0<\/strong><\/p>\n<pre><code>import { Component, ViewChild, ViewContainerRef } from '@angular\/core'; import { DynamicComponent } from '.\/dynamic.component';  @Component({   selector: 'my-app',   templateUrl: '.\/app.component.html',   styleUrls: ['.\/app.component.css'], }) export class AppComponent {   @ViewChild('dynamic', { read: ViewContainerRef })   private viewRef: ViewContainerRef;   private componentRef: ComponentRef&lt;DynamicComponent>;    showDynamicComponent(): void {     this.viewRef.clear();     this.componentRef = this.viewRef.createComponent(DynamicComponent); \/\/ \u0442\u0435\u043f\u0435\u0440\u044c \u0442\u0430\u043a   }    removeDynamicComponent(): void {     this.viewRef.clear();   } }<\/code><\/pre>\n<p>\u0421\u0442\u043e\u0438\u0442 \u0443\u0442\u043e\u0447\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u0445\u043e\u0442\u044c \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 <code>createComponent<\/code> \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0430\u0441\u044c, \u043c\u044b \u0432\u0441\u0435 \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c index, <a href=\"https:\/\/angular.io\/api\/core\/Injector\">injector<\/a>, <a href=\"https:\/\/angular.io\/api\/core\/NgModuleRef\">ngModuleRef<\/a> \u0438 projectableNodes, \u043d\u043e \u0443\u0436\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c.<\/p>\n<p>\u0410 \u0437\u0430 \u0441\u0447\u0435\u0442 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e <code>createComponent<\/code> \u0432\u0441\u0435 \u0442\u0430\u043a \u0436\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>ComponentRe<\/code><em>f<\/em>, \u043d\u0430\u043c \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043c\u0435\u043d\u044f\u0442\u044c \u043a\u043e\u0434 \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435 \u043d\u0430 \u043d\u043e\u0432\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430.<\/p>\n<h2>\u0412\u044b\u0432\u043e\u0434<\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0443\u0437\u043d\u0430\u043b\u0438, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0432 13 \u0432\u0435\u0440\u0441\u0438\u0438 Angular \u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u043e\u0442\u043b\u0438\u0447\u0438\u044f \u043e\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0441\u0442\u0430\u043b\u043e \u043f\u0440\u043e\u0449\u0435:<\/p>\n<ul>\n<li>\n<p>\u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u0435\u0441\u043f\u043e\u043a\u043e\u0438\u0442\u044c\u0441\u044f \u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0444\u0430\u0431\u0440\u0438\u043a\u0438<\/p>\n<\/li>\n<li>\n<p>\u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0438\u043d\u0436\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438<\/p>\n<\/li>\n<li>\n<p>\u0441\u0445\u043e\u0436\u0430\u044f \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430<\/p>\n<\/li>\n<\/ul>\n<p>Angular \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043b\u0443\u0447\u0448\u0435 \u0438 \u043b\u0443\u0447\u0448\u0435 \ud83d\ude42<\/p>\n<p>\u0411\u044b\u043b\u043e (Angular &lt;= 12):<\/p>\n<pre><code>export class AppComponent implements {   @ViewChild('dynamic', { read: ViewContainerRef })   private viewRef: ViewContainerRef;    private componentRef: ComponentRef&lt;DynamicComponent>;    constructor(     private readonly componentFactoryResolver: ComponentFactoryResolver   ) {}    showDynamicComponent(): void {     this.viewRef.clear();     const componentFactory =       this.componentFactoryResolver.resolveComponentFactory(DynamicComponent);     this.componentRef = this.viewRef.createComponent(componentFactory);   }    removeDynamicComponent(): void {     this.viewRef.clear();   } }<\/code><\/pre>\n<p>\u0421\u0442\u0430\u043b\u043e (Angular 13):<\/p>\n<pre><code>export class AppComponent {   @ViewChild('dynamic', { read: ViewContainerRef })   private viewRef: ViewContainerRef;    showDynamicComponent(): void {     this.viewRef.clear();     this.viewRef.createComponent(DynamicComponent);   }    removeDynamicComponent(): void {     this.viewRef.clear();   } }<\/code><\/pre>\n<p><a href=\"https:\/\/stackblitz.com\/edit\/angular-yqfxxn\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0441\u0442\u0430\u0440\u044b\u0439 \u043a\u043e\u0434<\/a>.<br \/><a href=\"https:\/\/stackblitz.com\/edit\/angular-mcbbub\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043d\u043e\u0432\u044b\u0439 \u043a\u043e\u0434<\/a>.<\/p>\n<p><strong>\u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438<\/strong><\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/stackblogger.com\/dynamic-components-angular\/\">https:\/\/stackblogger.com\/dynamic-components-angular\/<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/angular.io\/guide\/dynamic-component-loader\"><u>https:\/\/angular.io\/guide\/dynamic-component-loader<\/u><\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/betterprogramming.pub\/angular-13-features-ef528a9ae16f\"><u>https:\/\/betterprogramming.pub\/angular-13-features-ef528a9ae16f<\/u><\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/indepth.dev\/posts\/1054\/here-is-what-you-need-to-know-about-dynamic-components-in-angular\">https:\/\/indepth.dev\/posts\/1054\/here-is-what-you-need-to-know-about-dynamic-components-in-angular<\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/skyeng\/blog\/652855\/\"> https:\/\/habr.com\/ru\/company\/skyeng\/blog\/652855\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-330057","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/330057","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=330057"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/330057\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=330057"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=330057"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=330057"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}