Last active
October 31, 2023 20:49
-
-
Save weihungchin/a7b1c66cfa3e2c641908ae94b1671a76 to your computer and use it in GitHub Desktop.
Structural Directive Multiple Inputs - Angular
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Directive, Input, TemplateRef, ViewContainerRef } from '@angular/core'; | |
@Directive({ selector: '[myDir]'}) | |
export class MyDirective { | |
@Input() set myDir(text: string) { | |
console.log("text:", text); | |
} | |
@Input() set myDirGreet(greet: string) { | |
console.log(greet); | |
} | |
constructor( | |
private templateRef: TemplateRef<any>, | |
private viewContainer: ViewContainerRef) { ... } | |
....// ommitted for clarity | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- pass single input value --> | |
<div *myDir="'hi!'"></div> | |
<!-- pass multiple input values --> | |
<div *myDir="'hi!';greet:'good morning'"></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What syntax should be if we want to assign greet in the template with some component variable value like
<div *myDir="'hi!';greet: **someVar** "></div>