代码如下:
list.component.html
<nz-radio-group formControlName="radiostatus" [(ngModel)]="radioValue" (ngModelChange)="onChangeStatus($event)">
<label nz-radio nzValue="passed">Passed</label>
<label nz-radio nzValue="failed">Failed</label>
</nz-radio-group>
<div>
<textarea nz-input class="remarks-textarea" type="text" name="otherRemark" formControlName="remark" [(ngModel)]="otherRemark"
[nzAutosize]="{ minRows: 3, maxRows: 3 }"></textarea>
</div>
如何show
拥有div
的{{1}},当在textarea
中选择radio button
时它将显示{{1} }点击failed
。
预先感谢
答案 0 :(得分:1)
答案 1 :(得分:1)
答案 2 :(得分:1)
使用类似下面的示例:
HTML:
PASS src/stackoverflow/59281612/index.spec.tsx
TestContainer
✓ should pass (13ms)
-----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
-----------|----------|----------|----------|----------|-------------------|
All files | 100 | 100 | 100 | 100 | |
index.tsx | 100 | 100 | 100 | 100 | |
-----------|----------|----------|----------|----------|-------------------|
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 5.037s, estimated 11s
组件ts:
<form [formGroup]="radioForm">
<nz-radio-group formControlName="radiostatus" [(ngModel)]="radioValue" (ngModelChange)="onChangeStatus($event)">
<label nz-radio nzValue="passed">Passed</label>
<label nz-radio nzValue="failed">Failed</label>
</nz-radio-group>
<div *ngIf="radioValue === 'failed'">
<textarea nz-input class="remarks-textarea" type="text" name="otherRemark" formControlName="remark" [(ngModel)]="otherRemark"
[nzAutosize]="{ minRows: 3, maxRows: 3 }"></textarea>
</div>
</form>
您也可以使用import { Component } from '@angular/core';
import { FormGroup, FormControl } from '@angular/forms';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
radioForm = new FormGroup({
radiostatus: new FormControl(''),
remark: new FormControl('')
});
onChangeStatus($event){
console.log($event);
}
}
之类的符号代替[hidden]="radioValue !== 'failed'"