【发布时间】:2014-03-03 02:42:14
【问题描述】:
我有一个使用 ng-model 调用选项的选择。它工作得很好,但现在我正在尝试使用带有模型选项的输入来编辑数组中的选项列表,但它不起作用。
长话短说,输入将选项显示为逗号分隔值,但是一旦我编辑列表,选择就会中断。您可以在Plunker 中看到我的意思。
js 看起来是这样的:
var Select = function($scope) {
$scope.options =
[
"I live here!",
"By Boat",
"By Car",
"By Plane",
"By Bike",
"By Bus",
"Hitchhiking",
"Other"
];
$scope.form = {type : $scope.options[0]};
};
还有html:
<form class="col-md-12" ng-controller="Select">
<select class="form-control" ng-model="form.type" ng-options="opt for opt in options">
</select>
<textarea ng-model="options" class="form-control"></textarea>
</form>
我错过了什么?
【问题讨论】:
-
我找到了答案 [这里][1]!它需要一个新指令 :) [1]: stackoverflow.com/questions/17586159/…
标签: javascript angularjs angular-ngmodel