I have a trouble with angular-chosen
select, it's not updating ng-model
, when selected option changes.
angular-chosen
插件:
https ://github.com/leocaseiro/angular-chosen
plunker
重现此问题的
链接:http: //embed.plnkr.co/LqlLP3DnHj0hvDdyVqeU/
I have a trouble with angular-chosen
select, it's not updating ng-model
, when selected option changes.
angular-chosen
插件:
https ://github.com/leocaseiro/angular-chosen
plunker
重现此问题的
链接:http: //embed.plnkr.co/LqlLP3DnHj0hvDdyVqeU/
你有两个问题:
1)在官方文档中,他们说:
同样重要的是:如果您的 ngModel 为 null 或未定义,您必须在您的选择中手动包含一个空选项,否则您会遇到奇怪的错误
所以在你的控制器里面初始化变量:
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>
在这些更改之后,您的样本就像魅力一样
我希望它有帮助