{"id":403845,"date":"2024-06-29T17:21:54","date_gmt":"2024-06-29T17:21:54","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=403845"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-06-29T17:21:54","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=403845","title":{"rendered":"<span>\u041d\u0435\u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0439 *ngIf<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u0430\u043c \u043a\u043e\u0433\u0434\u0430-\u043d\u0438\u0431\u0443\u0434\u044c \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438, \u043f\u043e\u043a\u0430 <code>ngIf<\/code> \u0436\u0434\u0435\u0442 \u043e\u0442\u0432\u0435\u0442\u0430 \u043e\u0442 <code>async<\/code>-\u043f\u0430\u0439\u043f\u0430? \u0418\u043b\u0438, \u043c\u043e\u0436\u0435\u0442, \u0432\u044b \u043c\u0435\u0447\u0442\u0430\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432 <code>ngFor<\/code> \u0448\u0430\u0431\u043b\u043e\u043d \u0434\u043b\u044f \u043f\u0443\u0441\u0442\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430? \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432\u044b \u0431\u0440\u043e\u0441\u0438\u043b\u0438 \u044d\u0442\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432\u0430\u043c \u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u044d\u0442\u0438\u0445 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432 \u0441\u0430\u043c\u043e\u043c\u0443. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0432 \u044d\u0442\u043e\u043c \u043d\u0435\u0442 \u043d\u0443\u0436\u0434\u044b! \u041e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0434\u0446\u0435\u043f\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u043e\u0439.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/846\/786\/3e2\/8467863e2df65db32cb31f4b16c822ef.png\" width=\"1561\" height=\"881\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/846\/786\/3e2\/8467863e2df65db32cb31f4b16c822ef.png\"\/><figcaption><\/figcaption><\/figure>\n<p><a href=\"https:\/\/angular.io\/api\/common\/NgForOf\"><u>NgForOf<\/u><\/a>, \u0431\u043e\u043b\u0435\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0430\u044f \u043a\u0430\u043a <code>ngFor<\/code>, \u2014 \u0437\u043d\u0430\u043a\u043e\u043c\u0430\u044f \u0432\u0441\u0435\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u0430 \u0441\u043f\u0438\u0441\u043a\u0430. \u0414\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0447\u0430\u0441\u0442\u043e \u0441\u043f\u0438\u0441\u043e\u043a \u0431\u044b\u0432\u0430\u0435\u0442 \u043f\u0443\u0441\u0442\u044b\u043c \u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u00ab\u041d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e\u00bb. \u042d\u0442\u0443 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c <a href=\"https:\/\/github.com\/angular\/angular\/issues\/14479\">\u0443\u0436\u0435 \u043f\u0440\u043e\u0441\u0438\u043b\u0438 \u043d\u0430 github<\/a> \u0438 \u0434\u0430\u0436\u0435 \u043d\u0430\u0431\u0440\u0430\u043b\u0438 169 \u043b\u0430\u0439\u043a\u043e\u0432. \u0412 \u0438\u0442\u043e\u0433\u0435 \u0435\u0435 \u0437\u0430\u0432\u0435\u0440\u043d\u0443\u043b\u0438, \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0435\u0436\u0435\u043b\u0430\u043d\u0438\u0435\u043c \u0440\u0430\u0437\u0434\u0443\u0432\u0430\u0442\u044c core-\u043f\u0430\u043a\u0435\u0442. \u041c\u044b \u0438 \u0442\u0430\u043a \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>ngIf<\/code> \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0434\u043b\u0438\u043d\u044b. \u041d\u043e \u0442\u043e\u0433\u0434\u0430 \u044d\u0442\u043e \u0440\u0430\u0437\u0434\u0443\u0435\u0442 \u0431\u0430\u043d\u0434\u043b \u0441\u0430\u043c\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0422\u0430\u043a \u0447\u0442\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u0443 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c, \u0434\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044f \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u043a\u043e\u0434\u0430.<\/p>\n<blockquote>\n<p><em>* \u2014 \u044d\u0442\u043e <\/em><a href=\"https:\/\/angular.io\/guide\/structural-directives#structural-directive-syntax-reference\"><em><u>\u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u0430\u0445\u0430\u0440<\/u><\/em><\/a><em> \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0438\u043d\u043f\u0443\u0442\u043e\u0432<\/em><\/p>\n<\/blockquote>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u0440\u043e\u0447\u043b\u0438 \u0438 \u043f\u043e\u043d\u044f\u043b\u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430 \u0432\u044b\u0448\u0435, \u0442\u043e \u0432\u0430\u0448 IQ \u0438\u0437\u043c\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u0447\u0435\u0442\u044b\u0440\u0435\u0445\u0437\u043d\u0430\u0447\u043d\u044b\u043c \u0447\u0438\u0441\u043b\u043e\u043c. \u041d\u043e \u043d\u0430 \u0434\u0435\u043b\u0435 \u0432\u0441\u0435 \u043d\u0435 \u0442\u0430\u043a \u0441\u043b\u043e\u0436\u043d\u043e, \u043a\u0430\u043a \u043a\u0430\u0436\u0435\u0442\u0441\u044f. \u041f\u043e \u0441\u0443\u0442\u0438, \u0435\u0441\u043b\u0438 \u0431\u044b \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b \u0438\u043d\u043f\u0443\u0442 <code>ngForEmpty<\/code>, \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c: <code>*ngFor=\"let item of items empty template\"<\/code> \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c <a href=\"https:\/\/angular.io\/guide\/template-reference-variables\"><u>template reference-\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e<\/u><\/a> \u0434\u043b\u044f \u043f\u0443\u0441\u0442\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f. \u0422\u0430\u043a \u0447\u0442\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u0432\u043e\u044e \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0443 \u0441 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440\u043e\u043c <code>ngFor<\/code>, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a\u043e\u0439 \u0438\u043d\u043f\u0443\u0442:<\/p>\n<pre><code class=\"dart\">@Directive({    selector: '[ngFor][ngForOf][ngForEmpty]', }) export class TuiForDirective implements OnChanges {    @Input()    ngForOf = [];     @Input()    ngForEmpty: TemplateRef&lt;{}>;     private ref?: EmbeddedViewRef&lt;{}>;     constructor(private readonly vcr: ViewContainerRef) {}     ngOnChanges() {        this.ref?.destroy();         if (this.ngForOf?.length === 0) {            this.ref = this.vcr.createEmbeddedView(this.ngForEmpty);        }    } } <\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0438 \u0432\u0441\u0435! \u041a\u043e\u0433\u0434\u0430 <code>ngFor<\/code> \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f, \u043c\u044b \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0430\u0435\u043c \u043d\u0430\u0448 \u0448\u0430\u0431\u043b\u043e\u043d \u043f\u0443\u0441\u0442\u043e\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430, \u0438 \u0435\u0441\u043b\u0438 \u043c\u0430\u0441\u0441\u0438\u0432 \u043f\u0443\u0441\u0442\u043e\u0439, \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0435\u0433\u043e. \u0422\u0430\u043a\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u0434\u0430 \u043d\u0430\u0448 \u0431\u0430\u043d\u0434\u043b \u043f\u043e\u0442\u044f\u043d\u0435\u0442!<\/p>\n<h2>\u041d\u0435\u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0439 ngIf<\/h2>\n<p><code>NgIf<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u044b \u0438\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u043e \u0438\u043d\u043e\u0433\u0434\u0430 \u044d\u0442\u043e\u0433\u043e \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u0442\u044c \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0438 \u043e\u0448\u0438\u0431\u043a\u0443. \u0427\u0442\u043e \u0435\u0441\u043b\u0438 \u044f \u0441\u043a\u0430\u0436\u0443 \u0432\u0430\u043c, \u0447\u0442\u043e \u044d\u0442\u043e\u043c\u0443 \u0431\u0435\u0437\u0443\u043c\u043d\u043e\u043c\u0443 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0443 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u0432\u0441\u0435\u0433\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0441\u0442\u0440\u043e\u043a?<\/p>\n<pre><code class=\"xml\">&lt;p *ngIf=\"value$ | async as value else default or loading but error\">   {{value}} &lt;\/p><\/code><\/pre>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u043c <code>ngIf<\/code> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>or<\/code> \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0438 <code>but<\/code> \u0434\u043b\u044f \u043e\u0448\u0438\u0431\u043a\u0438. \u041d\u0438\u0436\u0435 \u044f \u043f\u0440\u0438\u0432\u0435\u043b \u0437\u0430\u0433\u043e\u0442\u043e\u0432\u043a\u0443 \u0442\u0430\u043a\u043e\u0439 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b \u0441 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c\u0438:<\/p>\n<pre><code class=\"dart\">@Directive({   selector: '[ngIf][ngIfOr],[ngIf][ngIfBut]' }) export class NgIfAugmentedDirective&lt;T> implements OnChanges {   \/\/ \u0421\u043b\u0435\u0434\u0438\u043c \u0437\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c   @Input()   ngIf: unknown = false;    \/\/ \u0421\u043b\u0435\u0434\u0438\u043c \u0437\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u043c \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u043c   @Input()   ngIfThen: TemplateRef&lt;NgIfContext&lt;T>> = this.templateRef;    \/\/ \u0421\u043b\u0435\u0434\u0438\u043c \u0437\u0430 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u043c \u201celse\u201d   @Input()   ngIfElse: TemplateRef&lt;NgIfContext&lt;T>> | null = null;    \/\/ \u0428\u0430\u0431\u043b\u043e\u043d \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438   @Input()   ngIfOr: TemplateRef&lt;NgIfContext&lt;T>> | null = null;    \/\/ \u0428\u0430\u0431\u043b\u043e\u043d \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043a\u0438   @Input()   ngIfBut: TemplateRef&lt;NgIfContext&lt;T>> | null = null;    constructor(     \/\/ \u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430 *ngIf      private readonly directive: NgIf&lt;T>,     private readonly templateRef: TemplateRef&lt;NgIfContext&lt;T>>   ) {} }<\/code><\/pre>\n<p>\u041c\u044b \u0438\u043d\u0436\u0435\u043a\u0442\u0438\u043c <code>ngIf<\/code>, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u0434\u0435\u043b\u0430\u043b \u0432\u0441\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0437\u0430 \u043d\u0430\u0441. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>null<\/code> \u043a\u0430\u043a \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0435\u0433\u043e \u0432\u044b\u0434\u0430\u0435\u0442 <code>async<\/code>-\u043f\u0430\u0439\u043f, \u043f\u043e\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0435 \u0435\u0449\u0435 \u043d\u0435 \u043f\u0440\u0438\u043b\u0435\u0442\u0435\u043b\u0438. \u0414\u043b\u044f \u043e\u0448\u0438\u0431\u043a\u0438 \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0447\u0435\u0440\u0435\u0437 <code>instanceof Error<\/code>.<\/p>\n<p>\u0412\u0441\u0435, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e, \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u0438 <code>ngOnChanges<\/code>. \u041c\u044b \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u0439 \u0448\u0430\u0431\u043b\u043e\u043d \u0432 <code>ngIf<\/code>. \u041f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u043d\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"dart\">ngOnChanges() {   \/\/ \u041f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0435\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b   \/\/ \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0448\u0430\u0431\u043b\u043e\u043d \u0432 ngIfElse \u0438 \u0432\u044b\u0445\u043e\u0434\u0438\u043c   if (this.ngIf === null &amp;&amp; this.ngIfOr) {     this.directive.ngIfElse = this.ngIfOr;      return;   }    \/\/ \u0414\u0430\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u0430 Error \u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0442, \u0447\u0442\u043e \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c   \/\/ \u0448\u0430\u0431\u043b\u043e\u043d \u0432 ngIfThen \u0438 \u0434\u0435\u043b\u0430\u0435\u043c \u0440\u0430\u043d\u043d\u0438\u0439 \u0432\u044b\u0445\u043e\u0434   if (this.ngIf instanceof Error &amp;&amp; this.ngIfBut) {     this.directive.ngIfThen = this.ngIfBut;      return;   }    \/\/ \u0415\u0441\u043b\u0438 \u043d\u0438 \u0442\u043e \u043d\u0438 \u0442\u043e \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043b\u043e\u0441\u044c,   \/\/ \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u0448\u0430\u0431\u043b\u043e\u043d\u044b   if (this.directive.ngIfThen !== this.ngIfThen) {     this.directive.ngIfThen = this.ngIfThen;   }    if (this.directive.ngIfElse !== this.ngIfElse) {     this.directive.ngIfElse = this.ngIfElse;   } } <\/code><\/pre>\n<p>\u0427\u0435\u0442\u044b\u0440\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0438 \u0447\u0435\u0442\u044b\u0440\u0435 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u043a\u043e\u0434\u0430 \u2014 \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440. \u0414\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430 \u0441\u043e\u0437\u0434\u0430\u0441\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u043c\u044b \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u043c \u0442\u043e\u0442 \u0438\u043b\u0438 \u0438\u043d\u043e\u0439 \u0448\u0430\u0431\u043b\u043e\u043d \u0447\u0435\u0440\u0435\u0437 \u0441\u0430\u0445\u0430\u0440 \u0438\u043b\u0438 \u044f\u0432\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b.<\/p>\n<h2>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/h2>\n<p><code>NgFor<\/code> \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 <code>async<\/code>-\u043f\u0430\u0439\u043f\u043e\u043c. \u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043a \u043d\u0430\u0448\u0435\u0439 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0432\u0441\u0435\u0433\u043e \u043f\u0430\u0440\u0443 \u0441\u0442\u0440\u043e\u043a. \u0418\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c <a href=\"https:\/\/stackblitz.com\/edit\/angular-augmented-directives\"><u>\u043d\u0430 \u044d\u0442\u043e\u043c StackBlitz.<\/u><\/a><\/p>\n<p>\u0414\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b Angular \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0430\u0437\u0431\u0438\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u043d\u0430 \u0447\u0430\u0441\u0442\u0438. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0432\u0435\u0441\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432 \u043d\u0430 \u043e\u0434\u0438\u043d \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0449\u0435 \u0431\u043e\u043b\u0435\u0435 \u0433\u0438\u0431\u043a\u043e. \u0414\u0430\u0436\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0435 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b \u0438 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u0430\u0445\u0430\u0440 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0442\u0430\u043a \u0436\u0435. \u0418\u043c\u0435\u0439\u0442\u0435 \u044d\u0442\u043e \u0432 \u0432\u0438\u0434\u0443, \u043a\u043e\u0433\u0434\u0430 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0440\u0430\u0437 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0441\u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0438\u0442\u044c \u043a\u0430\u043a\u043e\u0435-\u0442\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 ?<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/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\/articles\/580172\/\"> https:\/\/habr.com\/ru\/articles\/580172\/<\/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 article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u0430\u043c \u043a\u043e\u0433\u0434\u0430-\u043d\u0438\u0431\u0443\u0434\u044c \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438, \u043f\u043e\u043a\u0430 <code>ngIf<\/code> \u0436\u0434\u0435\u0442 \u043e\u0442\u0432\u0435\u0442\u0430 \u043e\u0442 <code>async<\/code>-\u043f\u0430\u0439\u043f\u0430? \u0418\u043b\u0438, \u043c\u043e\u0436\u0435\u0442, \u0432\u044b \u043c\u0435\u0447\u0442\u0430\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432 <code>ngFor<\/code> \u0448\u0430\u0431\u043b\u043e\u043d \u0434\u043b\u044f \u043f\u0443\u0441\u0442\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430? \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432\u044b \u0431\u0440\u043e\u0441\u0438\u043b\u0438 \u044d\u0442\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432\u0430\u043c \u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u044d\u0442\u0438\u0445 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432 \u0441\u0430\u043c\u043e\u043c\u0443. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0432 \u044d\u0442\u043e\u043c \u043d\u0435\u0442 \u043d\u0443\u0436\u0434\u044b! \u041e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0434\u0446\u0435\u043f\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u043e\u0439.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p><a href=\"https:\/\/angular.io\/api\/common\/NgForOf\"><u>NgForOf<\/u><\/a>, \u0431\u043e\u043b\u0435\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0430\u044f \u043a\u0430\u043a <code>ngFor<\/code>, \u2014 \u0437\u043d\u0430\u043a\u043e\u043c\u0430\u044f \u0432\u0441\u0435\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u0430 \u0441\u043f\u0438\u0441\u043a\u0430. \u0414\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0447\u0430\u0441\u0442\u043e \u0441\u043f\u0438\u0441\u043e\u043a \u0431\u044b\u0432\u0430\u0435\u0442 \u043f\u0443\u0441\u0442\u044b\u043c \u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u00ab\u041d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e\u00bb. \u042d\u0442\u0443 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c <a href=\"https:\/\/github.com\/angular\/angular\/issues\/14479\">\u0443\u0436\u0435 \u043f\u0440\u043e\u0441\u0438\u043b\u0438 \u043d\u0430 github<\/a> \u0438 \u0434\u0430\u0436\u0435 \u043d\u0430\u0431\u0440\u0430\u043b\u0438 169 \u043b\u0430\u0439\u043a\u043e\u0432. \u0412 \u0438\u0442\u043e\u0433\u0435 \u0435\u0435 \u0437\u0430\u0432\u0435\u0440\u043d\u0443\u043b\u0438, \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0435\u0436\u0435\u043b\u0430\u043d\u0438\u0435\u043c \u0440\u0430\u0437\u0434\u0443\u0432\u0430\u0442\u044c core-\u043f\u0430\u043a\u0435\u0442. \u041c\u044b \u0438 \u0442\u0430\u043a \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>ngIf<\/code> \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0434\u043b\u0438\u043d\u044b. \u041d\u043e \u0442\u043e\u0433\u0434\u0430 \u044d\u0442\u043e \u0440\u0430\u0437\u0434\u0443\u0435\u0442 \u0431\u0430\u043d\u0434\u043b \u0441\u0430\u043c\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0422\u0430\u043a \u0447\u0442\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u0443 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c, \u0434\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044f \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u043a\u043e\u0434\u0430.<\/p>\n<blockquote>\n<p><em>* \u2014 \u044d\u0442\u043e <\/em><a href=\"https:\/\/angular.io\/guide\/structural-directives#structural-directive-syntax-reference\"><em><u>\u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u0430\u0445\u0430\u0440<\/u><\/em><\/a><em> \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0438\u043d\u043f\u0443\u0442\u043e\u0432<\/em><\/p>\n<\/blockquote>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u0440\u043e\u0447\u043b\u0438 \u0438 \u043f\u043e\u043d\u044f\u043b\u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430 \u0432\u044b\u0448\u0435, \u0442\u043e \u0432\u0430\u0448 IQ \u0438\u0437\u043c\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u0447\u0435\u0442\u044b\u0440\u0435\u0445\u0437\u043d\u0430\u0447\u043d\u044b\u043c \u0447\u0438\u0441\u043b\u043e\u043c. \u041d\u043e \u043d\u0430 \u0434\u0435\u043b\u0435 \u0432\u0441\u0435 \u043d\u0435 \u0442\u0430\u043a \u0441\u043b\u043e\u0436\u043d\u043e, \u043a\u0430\u043a \u043a\u0430\u0436\u0435\u0442\u0441\u044f. \u041f\u043e \u0441\u0443\u0442\u0438, \u0435\u0441\u043b\u0438 \u0431\u044b \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b \u0438\u043d\u043f\u0443\u0442 <code>ngForEmpty<\/code>, \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c: <code>*ngFor=\"let item of items empty template\"<\/code> \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c <a href=\"https:\/\/angular.io\/guide\/template-reference-variables\"><u>template reference-\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e<\/u><\/a> \u0434\u043b\u044f \u043f\u0443\u0441\u0442\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f. \u0422\u0430\u043a \u0447\u0442\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u0432\u043e\u044e \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0443 \u0441 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440\u043e\u043c <code>ngFor<\/code>, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a\u043e\u0439 \u0438\u043d\u043f\u0443\u0442:<\/p>\n<pre><code class=\"dart\">@Directive({    selector: '[ngFor][ngForOf][ngForEmpty]', }) export class TuiForDirective implements OnChanges {    @Input()    ngForOf = [];     @Input()    ngForEmpty: TemplateRef&lt;{}>;     private ref?: EmbeddedViewRef&lt;{}>;     constructor(private readonly vcr: ViewContainerRef) {}     ngOnChanges() {        this.ref?.destroy();         if (this.ngForOf?.length === 0) {            this.ref = this.vcr.createEmbeddedView(this.ngForEmpty);        }    } } <\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0438 \u0432\u0441\u0435! \u041a\u043e\u0433\u0434\u0430 <code>ngFor<\/code> \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f, \u043c\u044b \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0430\u0435\u043c \u043d\u0430\u0448 \u0448\u0430\u0431\u043b\u043e\u043d \u043f\u0443\u0441\u0442\u043e\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430, \u0438 \u0435\u0441\u043b\u0438 \u043c\u0430\u0441\u0441\u0438\u0432 \u043f\u0443\u0441\u0442\u043e\u0439, \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0435\u0433\u043e. \u0422\u0430\u043a\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u0434\u0430 \u043d\u0430\u0448 \u0431\u0430\u043d\u0434\u043b \u043f\u043e\u0442\u044f\u043d\u0435\u0442!<\/p>\n<h2>\u041d\u0435\u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0439 ngIf<\/h2>\n<p><code>NgIf<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u044b \u0438\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u043e \u0438\u043d\u043e\u0433\u0434\u0430 \u044d\u0442\u043e\u0433\u043e \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u0442\u044c \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0438 \u043e\u0448\u0438\u0431\u043a\u0443. \u0427\u0442\u043e \u0435\u0441\u043b\u0438 \u044f \u0441\u043a\u0430\u0436\u0443 \u0432\u0430\u043c, \u0447\u0442\u043e \u044d\u0442\u043e\u043c\u0443 \u0431\u0435\u0437\u0443\u043c\u043d\u043e\u043c\u0443 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0443 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u0432\u0441\u0435\u0433\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0441\u0442\u0440\u043e\u043a?<\/p>\n<pre><code class=\"xml\">&lt;p *ngIf=\"value$ | async as value else default or loading but error\">   {{value}} &lt;\/p><\/code><\/pre>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u043c <code>ngIf<\/code> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>or<\/code> \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0438 <code>but<\/code> \u0434\u043b\u044f \u043e\u0448\u0438\u0431\u043a\u0438. \u041d\u0438\u0436\u0435 \u044f \u043f\u0440\u0438\u0432\u0435\u043b \u0437\u0430\u0433\u043e\u0442\u043e\u0432\u043a\u0443 \u0442\u0430\u043a\u043e\u0439 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b \u0441 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c\u0438:<\/p>\n<pre><code class=\"dart\">@Directive({   selector: '[ngIf][ngIfOr],[ngIf][ngIfBut]' }) export class NgIfAugmentedDirective&lt;T> implements OnChanges {   \/\/ \u0421\u043b\u0435\u0434\u0438\u043c \u0437\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c   @Input()   ngIf: unknown = false;    \/\/ \u0421\u043b\u0435\u0434\u0438\u043c \u0437\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u043c \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u043c   @Input()   ngIfThen: TemplateRef&lt;NgIfContext&lt;T>> = this.templateRef;    \/\/ \u0421\u043b\u0435\u0434\u0438\u043c \u0437\u0430 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u043c \u201celse\u201d   @Input()   ngIfElse: TemplateRef&lt;NgIfContext&lt;T>> | null = null;    \/\/ \u0428\u0430\u0431\u043b\u043e\u043d \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438   @Input()   ngIfOr: TemplateRef&lt;NgIfContext&lt;T>> | null = null;    \/\/ \u0428\u0430\u0431\u043b\u043e\u043d \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043a\u0438   @Input()   ngIfBut: TemplateRef&lt;NgIfContext&lt;T>> | null = null;    constructor(     \/\/ \u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430 *ngIf      private readonly directive: NgIf&lt;T>,     private readonly templateRef: TemplateRef&lt;NgIfContext&lt;T>>   ) {} }<\/code><\/pre>\n<p>\u041c\u044b \u0438\u043d\u0436\u0435\u043a\u0442\u0438\u043c <code>ngIf<\/code>, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u0434\u0435\u043b\u0430\u043b \u0432\u0441\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0437\u0430 \u043d\u0430\u0441. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>null<\/code> \u043a\u0430\u043a \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0435\u0433\u043e \u0432\u044b\u0434\u0430\u0435\u0442 <code>async<\/code>-\u043f\u0430\u0439\u043f, \u043f\u043e\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0435 \u0435\u0449\u0435 \u043d\u0435 \u043f\u0440\u0438\u043b\u0435\u0442\u0435\u043b\u0438. \u0414\u043b\u044f \u043e\u0448\u0438\u0431\u043a\u0438 \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0447\u0435\u0440\u0435\u0437 <code>instanceof Error<\/code>.<\/p>\n<p>\u0412\u0441\u0435, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e, \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u0438 <code>ngOnChanges<\/code>. \u041c\u044b \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u0439 \u0448\u0430\u0431\u043b\u043e\u043d \u0432 <code>ngIf<\/code>. \u041f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u043d\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"dart\">ngOnChanges() {   \/\/ \u041f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0435\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b   \/\/ \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0448\u0430\u0431\u043b\u043e\u043d \u0432 ngIfElse \u0438 \u0432\u044b\u0445\u043e\u0434\u0438\u043c   if (this.ngIf === null &amp;&amp; this.ngIfOr) {     this.directive.ngIfElse = this.ngIfOr;      return;   }    \/\/ \u0414\u0430\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u0430 Error \u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0442, \u0447\u0442\u043e \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c   \/\/ \u0448\u0430\u0431\u043b\u043e\u043d \u0432 ngIfThen \u0438 \u0434\u0435\u043b\u0430\u0435\u043c \u0440\u0430\u043d\u043d\u0438\u0439 \u0432\u044b\u0445\u043e\u0434   if (this.ngIf instanceof Error &amp;&amp; this.ngIfBut) {     this.directive.ngIfThen = this.ngIfBut;      return;   }    \/\/ \u0415\u0441\u043b\u0438 \u043d\u0438 \u0442\u043e \u043d\u0438 \u0442\u043e \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043b\u043e\u0441\u044c,   \/\/ \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u0448\u0430\u0431\u043b\u043e\u043d\u044b   if (this.directive.ngIfThen !== this.ngIfThen) {     this.directive.ngIfThen = this.ngIfThen;   }    if (this.directive.ngIfElse !== this.ngIfElse) {     this.directive.ngIfElse = this.ngIfElse;   } } <\/code><\/pre>\n<p>\u0427\u0435\u0442\u044b\u0440\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0438 \u0447\u0435\u0442\u044b\u0440\u0435 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u043a\u043e\u0434\u0430 \u2014 \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440. \u0414\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430 \u0441\u043e\u0437\u0434\u0430\u0441\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u043c\u044b \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u043c \u0442\u043e\u0442 \u0438\u043b\u0438 \u0438\u043d\u043e\u0439 \u0448\u0430\u0431\u043b\u043e\u043d \u0447\u0435\u0440\u0435\u0437 \u0441\u0430\u0445\u0430\u0440 \u0438\u043b\u0438 \u044f\u0432\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b.<\/p>\n<h2>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/h2>\n<p><code>NgFor<\/code> \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 <code>async<\/code>-\u043f\u0430\u0439\u043f\u043e\u043c. \u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043a \u043d\u0430\u0448\u0435\u0439 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0432\u0441\u0435\u0433\u043e \u043f\u0430\u0440\u0443 \u0441\u0442\u0440\u043e\u043a. \u0418\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c <a href=\"https:\/\/stackblitz.com\/edit\/angular-augmented-directives\"><u>\u043d\u0430 \u044d\u0442\u043e\u043c StackBlitz.<\/u><\/a><\/p>\n<p>\u0414\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b Angular \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0430\u0437\u0431\u0438\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u043d\u0430 \u0447\u0430\u0441\u0442\u0438. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0432\u0435\u0441\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432 \u043d\u0430 \u043e\u0434\u0438\u043d \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0449\u0435 \u0431\u043e\u043b\u0435\u0435 \u0433\u0438\u0431\u043a\u043e. \u0414\u0430\u0436\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0435 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b \u0438 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u0430\u0445\u0430\u0440 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0442\u0430\u043a \u0436\u0435. \u0418\u043c\u0435\u0439\u0442\u0435 \u044d\u0442\u043e \u0432 \u0432\u0438\u0434\u0443, \u043a\u043e\u0433\u0434\u0430 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0440\u0430\u0437 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0441\u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0438\u0442\u044c \u043a\u0430\u043a\u043e\u0435-\u0442\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 ?<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/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\/articles\/580172\/\"> https:\/\/habr.com\/ru\/articles\/580172\/<\/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-403845","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/403845","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=403845"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/403845\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=403845"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=403845"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=403845"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}