Skip to content

Instantly share code, notes, and snippets.

@weihungchin
Last active October 31, 2023 20:49
Show Gist options
  • Save weihungchin/a7b1c66cfa3e2c641908ae94b1671a76 to your computer and use it in GitHub Desktop.
Save weihungchin/a7b1c66cfa3e2c641908ae94b1671a76 to your computer and use it in GitHub Desktop.
Structural Directive Multiple Inputs - Angular
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
}
<!-- pass single input value -->
<div *myDir="'hi!'"></div>
<!-- pass multiple input values -->
<div *myDir="'hi!';greet:'good morning'"></div>
@dmitrykondratenko86
Copy link

dmitrykondratenko86 commented Oct 31, 2023

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment