Angular 2 why asterisk (*)

前端 未结 5 1622
谎友^
谎友^ 2020-12-02 11:52

In angular 2 document, * and template, we know that the *ngIf, *ngSwitch, *ngFor can be expanded to ng-template tag. My question is:

I think the ngIf or

5条回答
  •  借酒劲吻你
    2020-12-02 12:31

    Asterisk syntax is a syntatic sugar for more wordy template syntax which directive expands to under the hood, you are free to use any of these options.

    Quote from the docs:

    The asterisk is "syntactic sugar". It simplifies ngIf and ngFor for both the writer and the reader. Under the hood, Angular replaces the asterisk version with a more verbose form.

    The next two ngIf examples are effectively the same and we may write in either style:

    
    
    
    

    Our heroes are true!

提交回复
热议问题