2013-11-20 39 views
1

工作版本角不工作1.0.7 plunkrngInclude曾在1.0.7但1.2.1

不工作的版本1.2.1角plunkr

在角1.0.7,以下ngInclude运行良好:

  <li class="dropdown" id="header_notification_bar" data-ng-include="" src="'notifications.tpl.html'" data-ng-controller="NotificationsCtrl"></li> 

notifications.tp.html看起来是这样的:

<a href="#" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true"> 
    <i class="icon-warning-sign"></i> 
    <span class="badge">{{notifications.length}}</span> 
</a> 
<ul class="dropdown-menu extended notification"> 
    <li> 
     <p>You have {{notifications.length}} new notifications</p> 
    </li> 
    <li> 
      <ul class="dropdown-menu-list scroller" scroller style="height: 250px"> 
       <li data-ng-repeat="n in notifications" > 
        <a href="#"> 
         <span class="label label-success"><i class="icon-plus"></i></span> 
         {{n.summary}} 
        <span class="time">{{n.time}}</span> 
        </a> 
       </li> 
      </ul> 
    </li> 
    <li class="external" > 
     <a href="#">See all notifications <i class="m-icon-swapright"></i></a> 
    </li> 
</ul> 

在Angular 1.2.1中,模板被加载,但看起来该视图没有绑定到控制器/范围。

如果您运行上面的2个plunk并单击感叹号,您将看到只有Angular 1.0.7显示通知项目。

我已阅读“从1.0迁移到1.2”文档,发现here,但没有看到任何相关内容。也许我错过了一些东西。

任何帮助?

感谢, 丹

+1

我没有看到底层原因 - 与由ngInclude和ngController创建的作用域不再共享 - 但将ng-controller声明移动到包装ul中似乎是一种解决方法。 [Plunk](http://plnkr.co/edit/0jfPVZYWwVY5BD7pOcwc?p=preview) – Sarah

回答

2

它看起来是一个变化在通过控制器通过对由NG-包括。正如@Sarah指出的那样,这可能是一个范围变化。

Here is a plunker这是工作。

我将ng-controller移入模板本身,它似乎再次工作。但不得不将模板包装在一个div(不理想,我知道)。

<div data-ng-controller="NotificationsCtrl"> 

我还添加了模板srcng-include,因为它是一个有点清洁器方式:

<li class="dropdown" id="header_notification_bar" data-ng-include="'notifications.tpl.html'"></li> 

希望这有助于。

+0

以下是相关更改:https://github.com/angular/angular.js/commit/909cabd36d779598763cc358979ecd85bb40d4d7 – KayakDave