【问题标题】:ng-include: Access child scope issueng-include:访问子范围问题
【发布时间】:2016-10-03 06:10:15
【问题描述】:

我在我的应用程序中使用 DayPilot Scheduler,但遇到以下问题。

home.html:

<div class="container-fluid">
    <daypilot-scheduler id="scheduler" daypilot-config="schedulerConfig" daypilot-events="events"></daypilot-scheduler>
</div>

我像这样在我的控制器中访问 daypilot 调度程序:

$scope.scheduler;

当 daypilot 指令像上面的 home.html 一样直接位于 home.html 内时,此方法有效,但当我将 daypilot 与 ng-include 一起包含时返回 undefined:

<div class="container-fluid">
    <div ng-include src="'partials/partial1.html'"></div>
</div>

部分1.html:

<section>   
    <daypilot-scheduler id="scheduler" daypilot-config="schedulerConfig" daypilot-events="events"></daypilot-scheduler>
</section>

如果它包含在 ng-include 中,$scope.scheduler 将返回 undefined。调度器作为 $$childeTail.scheduler 放在 $$childTail 下。

我做错了什么,如何访问 $$childTail?

【问题讨论】:

  • 尝试使用 $parent
  • 你能在 Plunker 中复制一个小例子吗?

标签: javascript angularjs angularjs-ng-include daypilot


【解决方案1】:

尝试将$parent. 前缀添加到id 属性的值。所以 partial1.html 将是:

<section>   
    <daypilot-scheduler id="$parent.scheduler" daypilot-config="schedulerConfig" daypilot-events="events"></daypilot-scheduler>
</section>

像往常一样在控制器中访问它:

$scope.scheduler;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-06
    • 1970-01-01
    • 2017-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多