یادداشتهای علی انصاری

۲ مطلب در فروردين ۱۳۹۶ ثبت شده است

برای نصب افلاین دات نت 3.5 در ویندوز 10، دستور زیر را اجرا کنید (در CMD که Run as Administrator شده است). فرض می کنیم درایو دارنده Installer ویندوز(سورس نصبی ویندوز)  D است

Dism /online /enable-feature /featurename:NetFX3 /All /Source:D:\sources\sxs /LimitAccess


Link

۱ نظر موافقین ۰ مخالفین ۰ ۲۸ فروردين ۹۶ ، ۱۴:۰۶
علی انصاری

ViewContainer (Structural Directives)

Reference


Since Angular 2* we can use ViewContainer simplifying structural directives authoring like ngIf.

We don’t require to manually deal with creating the View, setting up the resulting DOM elements and connecting change detection. The ViewContainer will deal with these for us resulting in the following code.

import {ViewContainerRef, TemplateRef} from '@angular/core'

@Directive({
  selector: '[myIf]'
})
export class myIf {
  private view;
  
  constructor(private container: ViewContainerRef, 
    private template: TemplateRef<any>) { }
    
  @Input() 
  set myIf(expression: boolean) {
    if (expression) {
     this.view = this.container.createEmbeddedView(this.template);
    } else {
     this.view.destroy();
    }
  };
}
Let’s see an example of how we would use it
<div>
<h2 *myIf="show">Hello {{name}}</h2> <-- EmbeddedView
<button (click)="show=!show">
Toggle
</button>
</div>

This is syntax sugar for

<template [myIf]="show">     <-- ViewContainerRef
<h2>Hello {{name}}</h2> <-- TemplateRef
</template>
۰ نظر موافقین ۰ مخالفین ۰ ۲۴ فروردين ۹۶ ، ۱۴:۱۱
علی انصاری