angularjs - Angular ui.select 未绑定(bind)到 ng-model

标签 angularjs angular-ui-select

我正在使用 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/

相关文章:

javascript - angular- ui-select - 如何将对象属性绑定(bind)到 ng-model

javascript - 如何从嵌套的 ng-repeat 中调用多个 angularjs 服务调用

javascript - 使用基于 Cookie 的 REST 后端时在 AngularJS 中进行身份验证?

regex - ng-pattern 在正则表达式应该禁止它时允许空间

java - 将 AngularJS 与 JSP 页面集成

javascript - 如何使用名称和值(数字 ID)填充下拉列表?

javascript - 按日期分组但不按 Angular 分组

angularjs - 与 Bootstrap 模态一起使用时显示在模态后面的 Angular ui-select 选项

angularjs - 将新值添加到 bootstrap ui-select

javascript - 所选值未出现在 angular-ui-select 中