【问题标题】:How to access controller value in custom typeahead templates如何访问自定义预输入模板中的控制器值
【发布时间】:2017-03-09 06:58:01
【问题描述】:

我在控制器中有范围值。我需要在自定义类型提前模板中显示范围值。

但是自定义模板不会访问它总是显示为空的控制器值。

在我的场景中,我需要在自定义模板中显示“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>

演示:

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

【问题讨论】:

    标签: angularjs bootstrap-typeahead twitter-typeahead angular-ui-typeahead


    【解决方案1】:

    实际上,$scope.names 的 JSON 结构与 uib-typeahead 模板的要求不匹配。我更改了names 数组以匹配结构模板要求,如下所示.. 它可以工作。如果你想换一种方式,你可以保持数组不变,也可以对模板进行更改!

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

    working plnkr

    【讨论】:

    • 我需要在“从下拉列表中选择位置”下方显示“$scope.states”,并在来自控制器的自定义列表下方显示 $scope.names
    • @CodeMan 让我理解正确。您想将两个列表的项目显示为一个下拉列表的值吗?因此,我们在输入中输入的任何内容都会被两个列表建议。对吗?
    • @CodeMan 我可以让它显示,但您将无法从我们强制显示的列表中选择任何内容。如果您也希望能够从该列表中进行选择,则需要连接两个列表并传递给预先输入,但它们不会分开显示
    • 任何可能的分隔列表的方法
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-10-21
    • 1970-01-01
    • 2015-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多