我正在使用 angular ui.select,但在将所选值绑定(bind)到模型时遇到了问题。我正在尝试使用 ui.select ng-model="data"
设置对象的变量。但是由于某种原因,它不会选择值不会绑定(bind)到模型。这是我正在使用的代码:
<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>
在我的情况下,使用它不会将所选值绑定(bind)到模型。然后我使用了 $parent.data
确实可以工作,但是当我使用多个 ui-selects 时,一次只能工作一个。
一定是我做错了什么,感谢任何帮助。
最佳答案
这是一个常见的引用问题。
你可以使用一个对象作为 ng-model
ng-model="data.value"
或者你可以尝试在 Controller 内部初始化数据。
$scope.data = null;
或者您可以使用 John Papa's style guide 中描述的 controllerAs View 语法。 (这样您就可以避免一次又一次地面临同样的问题)。
<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>
关于angularjs - Angular ui.select 未绑定(bind)到 ng-model,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39352111/