Angular ui.select不绑定到ng模型

Jac*_*ack 3 angularjs angular-ui-select

我正在使用角度ui.select,我将选择的值绑定到模型时遇到问题.我正在尝试使用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>
Run Code Online (Sandbox Code Playgroud)

在我的情况下,使用它不会将选定的值绑定到模型.然后我使用$parent.data哪个确实有效,但是当我使用多个ui-choose时,只有一个能够一次工作.

一定有什么我做错了任何帮助表示赞赏.

Art*_*tem 8

这是一个常见的引用问题.

您可以将对象用作ng-model

ng-model="data.value"
Run Code Online (Sandbox Code Playgroud)

或者您可以尝试初始化控制器内的数据.

$scope.data = null;
Run Code Online (Sandbox Code Playgroud)

或者您可以使用控制器作为John Papa的样式指南中描述的视图语法(这样您将避免一次又一次地面对相同的问题).

<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>
Run Code Online (Sandbox Code Playgroud)