通过ng-click选择选项在使用AngularJS的chrome浏览器中不起作用
发布时间:2020-12-17 06:55:27 所属栏目:安全 来源:网络整理
导读:我需要使用ng-click以便我可以传递三个参数并根据选择在我的本地json中设置. select option id="" value=""--Select--/option option ng-repeat="comparison in comparisons" ng-click="setSkillComparisonOperator(index,comparison.sid,comparison.name)"
|
我需要使用ng-click以便我可以传递三个参数并根据选择在我的本地json中设置.
<select>
<option id="" value="">--Select--</option>
<option ng-repeat="comparison in comparisons" ng-click="setSkillComparisonOperator(index,comparison.sid,comparison.name)"
ng-selected="comparison.sid == data.value.comparisonOperator.sid">{{comparison.name}}</option>
</select>
我可以使用ng-model和ng-change如下. <select ng-model="item" ng-options="o.id as o.id for o in list" ng-change="onFunction(item)">{{item}}</select>
在这种情况下,我不能传递如下三个参数. <select ng-model="item" ng-options="o.id as o.id for o in list" ng-change="onFunction(o.id,o.name)">{{item}}</select>
解决方法
最后,我找到了解决方案.
JS fiddle link HTML页面是 <div ng-app="miniapp">
<div ng-controller="Ctrl">
<select ng-model="selectedColor" ng-options="color as color.name for color in colors" ng-init="selectedColor = check(color1,colors)" ng-change="setColor(selectedColor)">
<option value="">Select A Color</option>
</select>
<br/>
<br/>
Color Id: <span ng-bind="colorId"></span>
<br/>
Color name: <span ng-bind="color"></span>
<br/>
Color shade: <span ng-bind="shade"></span>
<br/>
</div>
</div>
Javascript是 var $scope;
var app = angular.module('miniapp',[]);
function Ctrl($scope) {
$scope.colorId = 4;
$scope.shade = null;
$scope.color = null;
$scope.color1 = {name:'Red',value: 'red',id:2};
$scope.colors = [
{name:'Red',shade: 'white',id:1},{name:'Orange',shade: 'red',id:2},{name:'Yellow',shade: 'blue',id:3},{name:'Green',shade: 'yellow',id:4},{name:'Blue',shade: 'indigo',id:5},{name:'Indigo',shade: 'violet',id:6},{name:'Violet',shade: 'orange',id:7}
];
$scope.check =function(selectedColor,colors){
var i = null;
for(i in colors){
if(colors[i].id == selectedColor.id){
return colors[i];
}
}
};
$scope.setColor= function(color){
$scope.colorId = color.id;
$scope.shade = color.shade;
$scope.color = color.name;
};
};
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
