【问题标题】:Difference with use of using Select as in ng-options与在 ng-options 中使用 Select 的区别
【发布时间】:2019-01-04 15:09:09
【问题描述】:

IE中的选择框在第一次使用时导致打开问题 identity as identity.identityName for identity in identityProofList track by identity.identityIdng-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 的对象数组。

  1. 两者有什么区别?

  2. 为什么 ng-repeat 会导致 IE11 出现问题。

【问题讨论】:

标签: angularjs internet-explorer-11 angularjs-ng-options


【解决方案1】:

两者有什么区别?

您是指ng-repeatng-options 之间的区别吗?

使用它们创建 DropdownList 的区别在于:

使用 ng-options 制作的下拉菜单允许选择的值是一个对象,而使用 ng-repeat 制作的下拉菜单必须是一个字符串。

更多详情,请查看AngularJS Select Boxes

为什么 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>

结果like this

【讨论】:

  • 感谢您的回答,但我要求使用 'select as' 语法和没有它的黑白差异,因为后者在 IE 上运行良好,而前一个不是,即 identity as identity.identityName for identity in identityProofList track by identity.identityId & @ 987654327@ 和 ng-repeat 也不适用于 IE,但我知道两者的区别
猜你喜欢
  • 2013-02-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多