添加ng-repeat导致错误:$ compile:ctreq

时间:2015-06-23 19:08:23

标签: javascript angularjs angularjs-directive angular-leaflet-directive

我有一个需要传单指令的自定义指令,所以我可以访问控制器:

restrict: 'E',
require: '^leaflet',
scope: {

},
template: "",
link: function(scope, element, attrs, controller) {

}

当我在应用程序的控制器中使用我的自定义指令而不实现ng-repeat时,它可以正常工作。像这样:

没有ng-repeat

的控制器HTML
<leaflet defaults="defaults" center="center" markers="markers" layers="layers" paths="paths">
  <ng-include src="/markers.html" />
  <my-directive 
    waypoints="wps">
  </my-directive>
</leaflet>

控制器的JS没有ng-repeat

$scope.wps = [[32.745,-117.2776],[32.693,-117.3188]];

但是,当我尝试添加ng-repeat时,我最终收到以下错误:

Error: [$compile:ctreq] http://errors.angularjs.org/1.3.12/$compile/ctreq?p0=leaflet&p1=myDirective

控制器的HTML ng-repeat

    <leaflet defaults="defaults" center="center" markers="markers" layers="layers" paths="paths">
        <ng-include src="/markers.html" />
        <my-directive 
            ng-repeat="(name, data) in routes"
            name="{{ name }}"
            waypoints="data.wps">
        </my-directive>
    </leaflet>

控制器的JS与ng-repeat

$scope.routes = {
  r1: {
    wps: [[32.745,-117.2776],[32.693,-117.3188]]
  }
}

我搞砸了什么?

1 个答案:

答案 0 :(得分:3)

你的指令前有<ng-include src="/markers.html" />。您需要明确关闭该标记。请参阅this bug report