angualr 如何根据第一个select的选项确定剩下select需要绑定什么数据
<p>Action:
<select name="actions" formControlName="action">
<option value="fromMarket">Get Apple from Market(Buyer:user,Seller:market)</option>
<option value="fromSupplier">Get Apple from Supplier(Buyer:market,Seller:supplier)</option>
</select>
</p>
<div class="form-group text-left" ng-if="state==fromMarket">
<p>Buyer:
<select name="buyer" formControlName="formBuyerID">
<option *ngFor="let buyer of allBuyers" value="{{buyer.buyerID}}">{{buyer.buyerID}}</option>
</select>
</p>
<p>Seller:
<select name="seller" formControlName="formSellerID">
<option *ngFor="let seller of allSellers" value="{{seller.sellerID}}">{{seller.sellerID}}</option>
</select>
</p>
</div>
就像上面的代码,第一个select有两个选项,这两个选项都是代表不同的buyer和seller。在angular.componnent.ts里面应该怎么去调用? 并且我在运行的时候出现了一个错误: ERROR Error: "Must supply a value for form control with name:'action'." 。 我应该在ngOnInit()怎么去加载数据?
在Angular中,你可以使用ngModel
指令来根据第一个select的选项确定剩下select需要绑定什么数据。ngModel
指令用于双向数据绑定,这意味着当你在页面上更改第一个select的值时,数据模型会自动更新。
以下是一个例子:
```html
```
在这个例子中,userSelect
是一个select,newUserSelect
是一个input。当你在页面上更改userSelect
的值时,newUserSelect
的值也会自动更新。
如果你想在newUserSelect
的值发生变化时,userSelect
的值也会自动更新,你可以使用ngModel
指令的value
属性:
```html
```
在这个例子中,newUserSelect
的值将会在userSelect
的值发生变化时自动更新。