Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

html - change the order of elements inside a DIV tag

I would like to change the order of elements inside a div dinamically in specific condition.

The original code is

<div class="radio radio-inline radio-primary">
  <input 
    id="allergyYes" 
    type="radio" 
    (click)="toggleAllergy($event)" 
    data-toggle="true" 
    [(ngModel)]="allergy.isAllergic" 
    [value]="1"
    name="allergyYes" 
  />
  <label for="allergyYes">{{selectedLanguage.yes}}</label>
</div>

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

1 Answer

0 votes
by (71.8m points)

You could use two templates and an ngif (3rd example in Description section).

This will display the content in the div if the expression evaluates to true, otherwise it will display the content from the ng-template if it evaluates to false.

<div class="radio radio-inline radio-primary" *ngIf="myVar === 'option-one';else elseBlock">
  <input id="allergyYes" 
    type="radio" 
    (click)="toggleAllergy($event)" 
    data-toggle="true" 
    [(ngModel)]="allergy.isAllergic" 
    [value]="1" 
    name="allergyYes" />
  <label for="allergyYes">{{selectedLanguage.yes}}</label>
</div>

<ng-template #elseBlock>
  <label for="allergyYes">{{selectedLanguage.yes}}</label>
  <input id="allergyYes" 
    type="radio" 
    (click)="toggleAllergy($event)" 
    data-toggle="true" 
    [(ngModel)]="allergy.isAllergic" 
    [value]="1" 
    name="allergyYes" />
</ng-template>

@Component({
  // Component settings
})
export class TestComponent {
  public myVar = 'option-two'
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...