简体   繁体   English

角度UI选择不显示初始值

[英]Angular UI select does not display initial value

I have a form containing field "Partner". 我有一个包含“合作伙伴”字段的表单。 User should be able to set or change the partner by looking up for alternative partner and selecting an it so I use ui-select for the field. 用户应该能够通过查找替代合作伙伴并选择它来设置或更改合作伙伴,因此我在该字段中使用ui-select。 There's variable formNodeValue defined in the scope containing a 'partner' object with an ID and NAME. 范围中定义了变量formNodeValue ,其中包含带有ID和NAME的“伙伴”对象。 My problem is that when I load the form the field is blank although the formNodeValue is set to: 我的问题是,当我加载表单时,尽管formNodeValue设置为:

{
  id: 124,
  name: 'Partner name'
}

This is how I use ui-select: 这就是我使用ui-select的方式:

    <ui-select
            ng-model="formNodeValue"
            search-enabled="true">
        <ui-select-match>
            {{$select.selected.name}}
        </ui-select-match>
        <ui-select-choices
                refresh="doLookup($select.search)"
                repeat="item in (lookupItems | orderBy: 'name') track by item.id">
            <span ng-bind-html="item.name"></span>
        </ui-select-choices>
    </ui-select>

formNodeValue is actually a getter/setter function. formNodeValue实际上是一个getter / setter函数。 When it's called without arguments it returns an object. 在不带参数的情况下调用它会返回一个对象。 When it's called with arguments it work as a setter and returns no value. 当使用参数调用它时,它将作为设置器工作,并且不返回任何值。

As Ui-Select FAQs 作为Ui-Select常见问题解答

https://github.com/angular-ui/ui-select/wiki/FAQs https://github.com/angular-ui/ui-select/wiki/FAQs

ng-model not working with a simple variable on $scope ng-model无法在$ scope上使用简单变量

You cannot write:    
<ui-select ng-model="item"> <!-- Wrong -->
  [...]
</ui-select>

You need to write:    
<ui-select ng-model="item.selected"> <!-- Correct -->
  [...]
</ui-select>

Try setting formNodeValue like this 尝试像这样设置formNodeValue

{
  selected: {
    id: 124,
    name: 'Partner name'
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM