Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
167 views
in Technique[技术] by (71.8m points)

angular - How to pass input variable in structure directive?

There is a structure directive:

 @Directive({
        selector: '[loading]',
    })
    export class LoadingDirective {
        loadingFactory: ComponentFactory<LoadingComponent>;
        loadingComponent: ComponentRef<LoadingComponent>;

        @Input()
        set loading(loading: boolean) {}
        @Input('loadingSize') size: number;
    
    }

I have tried to pass size:

<span *loading="true size=20"></span>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
<span [loading]="true" [loadingSize]="20"></span>

Each input property stands on its own, and the * is not necessary

EDIT

change

        @Input()
        set loading(loading: boolean) {}

to

@Input() loading: boolean;

otherwise you are not doing anything with the value, since your setter function is empty


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...