angularjs - 与在 ng-options 中使用 Select 的区别
问题描述
IE 中的选择框在第一次使用时会导致打开问题
identity as identity.identityName for identity in identityProofList track by identity.identityId
orng-repeat
但当不使用时identity as
,它工作正常,也看不出选择框的功能有任何差异。
<select name="identityProof" ng-model="identityProof" ng-change="changeProofOfIdentity(identityProof)" ng-options="identity.identityName for identity in identityProofList track by identity.identityId" id="identityProofList" >
其中identityProofList 是具有属性identityName 和identityId 的对象数组。
两者有什么区别?
为什么
ng-repeat
会导致 IE11 出现问题。
解决方案
两者有什么区别?
你的意思是ng-repeat和ng-options之间的区别吗?
使用它们创建 DropdownList 的区别在于:
使用 ng-options 制作的下拉菜单允许选择的值是一个对象,而使用 ng-repeat 制作的下拉菜单必须是一个字符串。
更多详细信息,请查看AngularJS 选择框。
为什么 ng-repeat 导致 IE11 出现问题也与使用 .
根据您的代码,我使用以下代码创建了一个示例,它在我的 IE 浏览器(11.17134.1.0)上运行良好,您可以参考。
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
<p>Select a identity:</p>
<select ng-model="selectedidentity">
<option ng-repeat="x in identityProofList " value="{{x.identityId}}">{{x.identityName}}</option>
</select>
<h1>You selected: {{selectedidentity}}</h1><br />
<select name="identityProof" ng-model="identityProof" ng-change="changeProofOfIdentity(identityProof)"
ng-options="identity as identity.identityName for identity in identityProofList track by identity.identityId"
id="identityProofList"></select>
<h1>You selected: {{selectedvalue}}</h1>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function ($scope) {
$scope.identityProofList = [
{ identityId: "1001", identityName: "Admin" },
{ identityId: "1002", identityName: "User" },
{ identityId: "1003", identityName: "Customer" }
];
$scope.selectedvalue = "";
$scope.changeProofOfIdentity = function (identity) {
$scope.selectedvalue = identity.identityName;
}
});
</script>
结果是这样的。
推荐阅读
- javascript - 打破地图函数中的循环并移动
- excel - Excel公式从具有多个条件的字母数字单元格中提取数字
- python - 错误:安装 requirements.txt 时命令出错,退出状态为 1
- java - 验证存储在数据库中的 BCrypt 密码
- ruby-on-rails - Github 操作工作流 PG::ConnectionBad:无法连接到服务器:运行 bundle exec rake 时没有这样的文件或目录
- opencascade - pyOCCT 与 PythonOCC 的新项目(2020 年)
- android - DJI Android-UXSDKDemo Mavic 2 Enterprise 转北
- python - 如何根据条件从两个系列创建熊猫系列
- python - 确定值是否在另一个模数的不确定性范围内
- c# - 如果 IHostedService.StopAsync 方法的实现没有响应取消请求会怎样?