簡體   English   中英

角度UI選擇不顯示初始值

[英]Angular UI select does not display initial value

我有一個包含“合作伙伴”字段的表單。 用戶應該能夠通過查找替代合作伙伴並選擇它來設置或更改合作伙伴,因此我在該字段中使用ui-select。 范圍中定義了變量formNodeValue ,其中包含帶有ID和NAME的“伙伴”對象。 我的問題是,當我加載表單時,盡管formNodeValue設置為:

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

這就是我使用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實際上是一個getter / setter函數。 在不帶參數的情況下調用它會返回一個對象。 當使用參數調用它時,它將作為設置器工作,並且不返回任何值。

作為Ui-Select常見問題解答

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

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>

嘗試像這樣設置formNodeValue

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM