在angular中如何将 <td> <input nz-input type="number" class="form-control" formControlName="receiptCount" [value]="receiptCount"/> </td>这段代码变成只读不可更改
时间: 2024-03-20 09:42:11 浏览: 34
您可以使用 `disabled` 属性来禁用该输入框,这样它就会变成只读状态,无法更改。修改后的代码如下所示:
```html
<td>
<input nz-input type="number" class="form-control" formControlName="receiptCount" [value]="receiptCount" disabled/>
</td>
```
请注意,您也可以在使用 `disabled` 属性时将其绑定到组件中的一个布尔值,以便在需要时启用或禁用该输入框。
相关问题
<form nz-form [nzLayout]="'inline'" class="search-form"> <nz-row> <nz-col> <nz-form-item> <nz-form-label> 案件名称</nz-form-label> <nz-form-control> <nz-input-group> <input nz-input width="200px" value="" [(ngModel)]="q.ajmc" name="ajmc" placeholder="请输入案件名称"> </nz-input-group> </nz-form-control> </nz-form-item> </nz-col> <nz-col> <nz-form-item> <nz-form-label>案件编号</nz-form-label> <nz-form-control> <nz-input-group> <input nz-input width="200px" value="" [(ngModel)]="q.ajbh" name="ajbh" placeholder="请输入案件编号"> </nz-input-group> </nz-form-control> </nz-form-item> </nz-col> <nz-col> <button style="margin-top: 3px;" nz-button type="submit" [nzType]="'primary'" (click)="getDetail(true)">查询</button> <button nz-button type="reset" class="mx-sm">重置</button> </nz-col> </nz-row> </form>
在使用 TypeScript 编写上述表单时,你可以这样写:
```typescript
import { Component } from '@angular/core';
@Component({
selector: 'app-search-form',
templateUrl: './search-form.component.html',
styleUrls: ['./search-form.component.css']
})
export class SearchFormComponent {
q = {
ajmc: '',
ajbh: '',
};
onSubmit() {
// 处理表单提交事件
}
onReset() {
this.q.ajmc = '';
this.q.ajbh = '';
}
}
```
在这个例子中,我们使用了 Angular 框架来构建组件。在组件类中,我们定义了一个 `q` 对象来存储表单中的数据。当提交表单时,我们可以在 `onSubmit` 方法中处理表单提交事件,当重置表单时,我们可以在 `onReset` 方法中将 `q` 对象中的属性值设置为空字符串,从而实现表单重置的功能。
在 HTML 文件中,你可以这样写:
```html
<form nz-form [nzLayout]="'inline'" class="search-form" (ngSubmit)="onSubmit()">
<nz-row>
<nz-col>
<nz-form-item>
<nz-form-label> 案件名称</nz-form-label>
<nz-form-control>
<nz-input-group>
<input nz-input width="200px" [(ngModel)]="q.ajmc" name="ajmc" placeholder="请输入案件名称">
</nz-input-group>
</nz-form-control>
</nz-form-item>
</nz-col>
<nz-col>
<nz-form-item>
<nz-form-label>案件编号</nz-form-label>
<nz-form-control>
<nz-input-group>
<input nz-input width="200px" [(ngModel)]="q.ajbh" name="ajbh" placeholder="请输入案件编号">
</nz-input-group>
</nz-form-control>
</nz-form-item>
</nz-col>
<nz-col>
<button style="margin-top: 3px;" nz-button type="submit" [nzType]="'primary'">查询</button>
<button nz-button type="button" class="mx-sm" (click)="onReset()">重置</button>
</nz-col>
</nz-row>
</form>
```
在这个例子中,我们使用 `(ngSubmit)` 指令来监听表单的提交事件,并在事件发生时调用组件类中的 `onSubmit` 方法。在重置按钮中,我们使用 `(click)` 指令来监听按钮的点击事件,并在事件发生时调用组件类中的 `onReset` 方法。注意,重置按钮的类型应该为 `type="button"`,这样可以避免表单的提交事件被触发。
<td> <nz-select nzPlaceHolder="请选择采购明细" class="form-control" formControlName="buyOrderItem"> <nz-option *ngFor="let buyOrderItemOption of currentBuyOrderItems" [nzValue]="buyOrderItemOption" [nzLabel]="buyOrderItemOption.item?.serialNo + ' / ' + buyOrderItemOption.quantity" > </nz-option> </nz-select> </td> <td> <input nz-input type="number" class="form-control" formControlName="receiptCount" /> </td> 以上是angular的前端代码的两个td 现在想要将第一个td中的下拉框选中的单号对应的该单的数量自动填入第二td中 应该怎么编写更改这段代码
你可以在第一个td中的下拉框的change事件中,获取选中的采购明细的数量,并将其填入第二个td中的input中。具体代码如下:
```html
<td>
<nz-select nzPlaceHolder="请选择采购明细" class="form-control" formControlName="buyOrderItem" (ngModelChange)="onBuyOrderItemChange($event)">
<nz-option *ngFor="let buyOrderItemOption of currentBuyOrderItems" [nzValue]="buyOrderItemOption" [nzLabel]="buyOrderItemOption.item?.serialNo + ' / ' + buyOrderItemOption.quantity"></nz-option>
</nz-select>
</td>
<td>
<input nz-input type="number" class="form-control" formControlName="receiptCount" [value]="receiptCount" />
</td>
```
```typescript
// 在组件中添加以下代码
receiptCount: number;
onBuyOrderItemChange(buyOrderItem: any) {
this.receiptCount = buyOrderItem.quantity;
}
```
这样,当你选中第一个td中的下拉框选项时,第二个td中的input就会自动填入选中采购明细的数量。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![.zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![.zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)