Angular Chosen Localytics - ng 模型无法正常工作
Angular Chosen Localytics - ng model not working properly
我在使用 angular-chosen
select 时遇到问题,当 selected 选项更改时,它不会更新 ng-model
。
angular-chosen
插件:
https://github.com/leocaseiro/angular-chosen
Link 到 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
所以在你的控制器中初始化变量:
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>
经过这些更改后,您的示例很有魅力
希望对你有帮助
我在使用 angular-chosen
select 时遇到问题,当 selected 选项更改时,它不会更新 ng-model
。
angular-chosen
插件:
https://github.com/leocaseiro/angular-chosen
Link 到 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
所以在你的控制器中初始化变量:
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>
经过这些更改后,您的示例很有魅力
希望对你有帮助