Search
 
SCRIPT & CODE EXAMPLE
 

HTML

declare variable in html angular

We can just create directive like *ngIf and call it *ngVar

ng-var.directive.ts

@Directive({
    selector: '[ngVar]',
})
export class VarDirective {
    @Input()
    set ngVar(context: unknown) {
        this.context.$implicit = this.context.ngVar = context;

        if (!this.hasView) {
            this.vcRef.createEmbeddedView(this.templateRef, this.context);
            this.hasView = true;
        }
    }

    private context: {
        $implicit: unknown;
        ngVar: unknown;
    } = {
        $implicit: null,
        ngVar: null,
    };

    private hasView: boolean = false;

    constructor(
        private templateRef: TemplateRef<any>,
        private vcRef: ViewContainerRef
    ) {}
}

with this *ngVar directive we can use the following

<div *ngVar="false as variable">
      <span>{{variable | json}}</span>
</div>
Comment

angular html variable

We can just create directive like *ngIf and call it *ngVar

ng-var.directive.ts

@Directive({
    selector: '[ngVar]',
})
export class VarDirective {
    @Input()
    set ngVar(context: unknown) {
        this.context.$implicit = this.context.ngVar = context;

        if (!this.hasView) {
            this.vcRef.createEmbeddedView(this.templateRef, this.context);
            this.hasView = true;
        }
    }

    private context: {
        $implicit: unknown;
        ngVar: unknown;
    } = {
        $implicit: null,
        ngVar: null,
    };

    private hasView: boolean = false;

    constructor(
        private templateRef: TemplateRef<any>,
        private vcRef: ViewContainerRef
    ) {}
}

with this *ngVar directive we can use the following

<div *ngVar="false as variable">
      <span>{{variable | json}}</span>
</div>
Comment

angular variable in html

We can just create directive like *ngIf and call it *ngVar

ng-var.directive.ts

@Directive({
    selector: '[ngVar]',
})
export class VarDirective {
    @Input()
    set ngVar(context: unknown) {
        this.context.$implicit = this.context.ngVar = context;

        if (!this.hasView) {
            this.vcRef.createEmbeddedView(this.templateRef, this.context);
            this.hasView = true;
        }
    }

    private context: {
        $implicit: unknown;
        ngVar: unknown;
    } = {
        $implicit: null,
        ngVar: null,
    };

    private hasView: boolean = false;

    constructor(
        private templateRef: TemplateRef<any>,
        private vcRef: ViewContainerRef
    ) {}
}

with this *ngVar directive we can use the following

<div *ngVar="false as variable">
      <span>{{variable | json}}</span>
</div>
Comment

PREVIOUS NEXT
Code Example
Html :: angular read element from html by atribute name 
Html :: blizard.js print 
Html :: shchema keyref et key use 
Html :: jokes 
Html :: Magento Reindex Error : Catalog Search index process unknown error: "-//IETF//DTD HTML 2.0//EN" 405 Method Not Allowed 
Html :: get all values in hidden field with the same name 
Html :: react router preventing assets from being served 
Html :: how to add horizontal line in html without css 
Html :: komodo ide 13 
Html :: open in new tab html 
Html :: span blast html 
Html :: when I refresh my page it comes back to the same place html 
Html :: nativescript scrollview full height 
Html :: row span and column span in html example 
Html :: export wp page to static html/css 
Html :: html tandc 
Html :: laravel validation empty html tag 
Html :: how to remove dust from laptop 
Html :: partial url example 
Html :: how to make body element in html 
Html :: type animation js 
Html :: gafpa html cellule 
Html :: alert before delete in anchor tag 
Html :: sms link with body ios and android 
Html :: .ipynb to html 
Html :: HTML <del 
Html :: difference between section and div 
Html :: page html vierge 
Html :: how to add button in cell html 
Html :: render partial view to html string dotnet core 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =