0

我在controller中有範圍值。我需要在自定義類型提前模板中顯示範圍值。如何訪問自定義typeahead模板中的控制器值

但自定義模板將不會訪問控制器值,它總是顯示爲空。

在我的情況下,我需要在自定義模板中顯示「scope.names」。但它顯示爲空。

如何在自定義模板中顯示控制器值。

HTML:

<div class='container-fluid typeahead-demo' ng-controller="TypeaheadCtrl"> 
    <h4>Custom popup templates for typeahead's dropdown</h4> 
    <pre>Model: {{customPopupSelected | json}}</pre> 
    <input type="text" ng-model="customPopupSelected" placeholder="Custom popup template" uib-typeahead="state as state.name for state in statesWithFlags | filter:{name:$viewValue}" typeahead-popup-template-url="customPopupTemplate.html" class="form-control"> 
</div> 

DEMO:

https://plnkr.co/edit/HEf0lipdBP5ZyuciQsDo?p=preview

回答

0

你實際上具有在$scope.names的JSON結構和錯配什麼uib-typeahead模板需要。我改變了names數組,以匹配結構模板需要如下..和它的作品。如果你想做其他的事情,你可以保持數組相同,並對模板進行更改!

$scope.names=[{ 
    name: "Alabama" 
}, { 
    name: "Alaska" 
}, { 
    name: "Arizona" 
}]; 

working plnkr

+0

我需要在下面的「選擇位置從下拉」在下面自定義列表從控制器 – CodeMan

+0

顯示「$ scope.states」 和$ scope.names @CodeMan讓我明白正確。你想要顯示兩個列表的項目作爲一個下拉的值?因此,無論我們在輸入中輸入什麼,都會得到兩個列表的建議。那是對的嗎? – tanmay

+0

是的,我想顯示兩個下拉列表 – CodeMan

相關問題