gpt4 book ai didi

javascript - Angular Choose Localytics - ng 模型无法正常工作

转载 作者:行者123 更新时间:2023-12-03 04:13:43 25 4
gpt4 key购买 nike

我在使用 angular-chosen select 时遇到问题,当所选选项发生更改时,它不会更新 ng-model

Angular 选择插件: https://github.com/leocaseiro/angular-chosen

链接到 plunker 以重现此问题: http://embed.plnkr.co/LqlLP3DnHj0hvDdyVqeU/

最佳答案

您有两个问题:

1)在官方文档中他们说:

Also important: if your ngModel is null or undefined, you must manually include an empty option inside your select, otherwise you'll encounter strange off-by-one errors

所以在你的 Controller 内部初始化变量:

app.controller('MainCtrl', function($scope) {
$scope.selectedAgency = '';
$scope.values = [{id: 1,name: 'first'}, {id: 2,name: 'second'}];
});

2) 您在 index.html 中包含依赖项的顺序有问题。按如下方式更改顺序:

<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<link href="style.css" rel="stylesheet" />
<script data-require="jquery@*" data-semver="3.1.1" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script data-semver="1.4.0-rc.2" src="https://code.angularjs.org/1.4.0-rc.2/angular.js" data-require="angular.js@1.4.x"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-chosen-localytics/1.7.0/angular-chosen.min.js"></script>
<script src="chosen.jquery.js"></script>
<script src="angular-chosen.min.js"></script>
<script src="app.js"></script>

</head>

进行这些更改后,您的示例将变得魅力十足

希望对你有帮助

关于javascript - Angular Choose Localytics - ng 模型无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44230321/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com