Angularjs 角度用户界面。选择不绑定到ng模型
我正在使用angular ui.select,在将所选值绑定到模型时遇到问题。我正在尝试使用ui设置对象的变量。选择Angularjs 角度用户界面。选择不绑定到ng模型,angularjs,angular-ui-select,Angularjs,Angular Ui Select,我正在使用angular ui.select,在将所选值绑定到模型时遇到问题。我正在尝试使用ui设置对象的变量。选择ng model=“data”。但由于某些原因,它不会被选中,因为选定的值不会绑定到模型。这是我正在使用的代码: <ui-select ng-model="data" ng-disabled="disabled" theme='select2' style="min-width: 300px;" title="some title"> <ui-select-
ng model=“data”
。但由于某些原因,它不会被选中,因为选定的值不会绑定到模型。这是我正在使用的代码:
<ui-select ng-model="data" ng-disabled="disabled" theme='select2' style="min-width: 300px;" title="some title">
<ui-select-match placeholder="Select a credit status in the list">[[ $select.selected.variable ]]</ui-select-match>
<ui-select-choices repeat="options in options | filter: $select.search">
<p>[[ options.variable ]]</p>
</ui-select-choices>
</ui-select>
[$select.selected.variable]]
[[options.variable]]
在我的例子中,使用此选项不会将所选值绑定到模型。然后我使用了$parent.data
,它确实可以工作,但当我使用多个ui时,一次只能选择一个
一定是我做错了什么,感谢您的帮助。此Plunker是您正在使用的组件的演示: 尝试使用对象作为ng模型
ng-model="data.attribute"
由于您尝试使用多个ui选择,我建议您创建并初始化一个封装在$scope对象中的数组,如下所示:
$scope.selections = { selectedData = [] };
然后,对于ng模型,可以使用适当的点表示法:
ng-model="selections.selectedData"
希望这有帮助 这是一个常见的引用问题 可以将对象用作ng模型
ng-model="data.value"
或者您可以尝试初始化控制器内的数据
$scope.data = null;
或者,您可以使用中所述的controllerAs视图语法(这样可以避免一次又一次地遇到相同的问题)
[$select.selected.variable]]
[[options.variable]]
<div ng-controller="CustomerController as controllerName">
<ui-select ng-model="data" ng-disabled="disabled" theme='select2' style="min-width: 300px;" title="some title">
<ui-select-match placeholder="Select a credit status in the list">[[ $select.selected.variable ]]</ui-select-match>
<ui-select-choices repeat="options in options | filter: $select.search">
<p>[[ options.variable ]]</p>
</ui-select-choices>
</ui-select>
</div>