Mat*_*ood 3 javascript angularjs drop-down-menu angularjs-directive angularjs-ng-change
所以我有一些数据以逗号分隔的字符串.
sizes: "Small,Medium,Large,X Large,XX Large"
Run Code Online (Sandbox Code Playgroud)
我得到一个下拉列表,根据拆分该字符串显示值.
<select ng-options="choice as choice for (idx, choice) in val.sizes.split(',')"
ng-change="selected.product.set.size(choice);>
<option value="">Please select a size</option>
</select>
Run Code Online (Sandbox Code Playgroud)
使用ng-change:如何将所选值choice传递给函数?
您可以ng-model在ng-change回调中使用并访问它,或者直接传递它.
<select ng-model="selectedSize" ng-options="choice as choice for (idx, choice) in val.sizes.split(',')"
ng-change="selected.product.set.size(selectedSize)">
<option value="">Please select a size</option>
</select>
Run Code Online (Sandbox Code Playgroud)
angular.module('app', []).controller('ctrl', function($scope) {
$scope.sizes = "Small,Medium,Large,X Large,XX Large";
$scope.handleChange = function() {
console.log($scope.selectedSize)
}
});Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
<select ng-model="selectedSize" ng-options="choice as choice for (idx, choice) in sizes.split(',')" ng-change="handleChange()">
<option value="">Please select a size</option>
</select>
</div>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20154 次 |
| 最近记录: |