gpt4 book ai didi

angularjs - 如何在 Angular JS 中使用 ng-change 赋值

转载 作者:行者123 更新时间:2023-12-02 19:16:48 24 4
gpt4 key购买 nike

我有带有 Angular 模型的简单下拉绑定(bind)

<select ui-select2="{allowClear:true}" ng-model="product.Id" ng-change="{value = product.Id == 0}" data-placeholder="Select Warranty">
<option></option>
<option ng-repeat="product in products" value="{{product.Id}}">{{product.Code}}</option>
</select>

我如何根据 ng-change 中的某些条件分配值?

最佳答案

您选择的值定义为 ng-model 。上ng-change您可以从 Controller 调用方法并提供“选定的” ng-model到这个方法。

这是一个例子:

<select                                               
ng-model="product.Id"
ng-options="filter as filter.name for filter in groupList"
ng-change="changeItem(product.Id)"
></select>

Controller

$scope.changeItem = function(iem){

}

作为旁注,我会使用 ng-options而不是<option ng-repeat.....

关于angularjs - 如何在 Angular JS 中使用 ng-change 赋值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19089411/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com