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>
How i can assign value depending on some condition in ng-change?
The AngularJS ng-value directive is used to set the value attribute of an input element, or a select element. It is mainly used on <radio> and <option> elements to set the bound values when these elements are selected. It is supported by <input> and <select> elements.
$watch() function is used to watch the changes of variables in $scope object. Generally the $watch() function will create internally in Angularjs to handle variable changes in application.
Definition and UsageThe ng-bind directive tells AngularJS to replace the content of an HTML element with the value of a given variable, or expression. If the value of the given variable, or expression, changes, the content of the specified HTML element will be changed as well.
The ngInit directive allows you to evaluate an expression in the current scope. This directive can be abused to add unnecessary amounts of logic into your templates. There are only a few appropriate uses of ngInit : aliasing special properties of ngRepeat , as seen in the demo below.
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.
Here is an example:
<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){
}
As a side note, I would use ng-options
instead of <option ng-repeat.....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With