【问题标题】:Angular UI Bootstrap scope variables in custom typeahead template自定义预输入模板中的 Angular UI Bootstrap 范围变量
【发布时间】:2016-01-10 00:18:11
【问题描述】:

我正在使用 UI Bootstrap 的 typeahead 指令,并通过 typeahead-popup-template-url 添加了我自己的弹出模板。在该模板中,我想从父模板(即我使用了 typeahead 指令的模板)访问范围变量。这可能吗?

这是我正在尝试做的一个(损坏的)示例(“你好”应该出现在下拉列表中):http://plnkr.co/edit/ITT1SdRfUWeeN6n3aMqu?p=preview

我想在不修改 typeahead 指令的情况下执行此操作。如果有更优雅的解决方案,我不想乱用第三方 (uib) 代码。

【问题讨论】:

    标签: angularjs angular-ui-bootstrap


    【解决方案1】:

    在您的模板中,您需要引用 $parent 范围。变化:

    This should say "hello": {{hello}}</h1>
    

    收件人:

    This should say "hello": {{$parent.hello}}</h1>
    

    【讨论】:

    • 谢谢!我希望有一个简单的解决方案。
    【解决方案2】:

    Bootstrap、jquery ui、kendoui、yui 等 框架加起来是不是有点多啊O.o

    无论如何这篇文章可能会有所帮助:How to access parent scope from within a custom directive *with own scope* in AngularJS?

    【讨论】:

    • 如果我错了,请纠正我,但这似乎需要修改 uib 指令代码?请参阅我的问题以进行澄清。谢谢!
    • 也许在原版的基础上再写一个自定义指令?没有太多的角度经验知道这是否可能和一个好主意。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-31
    • 1970-01-01
    • 2016-06-26
    • 2017-09-13
    相关资源
    最近更新 更多