如何在angular js中使用ng-change赋值 [英] How to Assign value with ng-change in angular js

查看:38
本文介绍了如何在angular js中使用ng-change赋值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有角度模型的简单下拉绑定

I have simple drop-down bind with angular model

<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 中的某些条件分配值?

How i can assign value depending on some condition in ng-change?

推荐答案

您选择的值定义为 ng-model.在 ng-change 上,您可以从控制器调用一个方法,并将选定的"ng-model 提供给该方法.

Your selected value is defined as ng-model. On ng-change you can call a method from the controller and provide the "selected" ng-model to this method.

这是一个例子:

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

控制器

$scope.changeItem = function(iem){

}

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

As a side note, I would use ng-options instead of <option ng-repeat.....

这篇关于如何在angular js中使用ng-change赋值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆