該所選網頁加載與一個單選按鈕如何隱藏默認一個div是angular
組分:
如何設置功能部件通過默認加載頁面時隱藏div
。 div
只有點擊radio-button
才能加載。當在角2
`import { Component, OnInit } from '@angular/core';
@Component({
templateUrl: './radio-test.component.html',
styleUrls: ['./radio-test.component.css']
})
export class RadioTestComponent {
private selectedLink: string="Radio1";
setradio(e: string): void
{
this.selectedLink = e;
}
isSelected(name: string): boolean
{
if (!this.selectedLink) {
return false;
} return (this.selectedLink === name);
}
}
`
在Html
:
如何調用從組件功能,以便在默認情況下沒有div
應顯示。
<div class="jumbotron">
<div class="radio">
<label>
<input type="radio" name="gender" value="Radio" (click)="setradio('Radio1')" >
Radio 1
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="gender" value="Female" (click)="setradio('Radio2')" ngModel>
Radio 2
</label>
</div>
<div *ngIf="isSelected('Radio1')" >
<div style="height:52px;width:300px;background-color: grey;">Radio button 1 is selected </div>
</div>
<div *ngIf="isSelected('Radio2')">
<div style="height:52px;width:300px;background-color: lightgrey;">Radio button 2 is selected </div>
</div>
</div>
爲什麼使用函數u,你可以簡單地做,而無需使用功能 – Ajith
**我怎麼能做到這一點沒有功能。功能是用於顯示Div點擊** –
我的理解是,單擊單選按鈕時顯示div。 – Ajith