我在ng-include中遇到嵌套指令的问题。情况如下: 我有这样的模板:
ng-include src="includePath" quick-edit=""
这包括带有嵌套ng-includes模板的文件,代码:
.container ng-init="initialize()" style="padding:20px 50px"
.row
.col-xs-6.col-xs-offset-3
img ng-src="{{shop.logo}}"
.row ng-repeat="section in mainPageSections"
section
ng-include src="section.source"
一切正常但是在第一部分 - 包括我有指令快速编辑看起来:
'use strict'
app = angular.module('saasPlatform')
app.directive 'quickEdit', ['$rootScope', '$compile', ($rootScope, $compile) ->
restrict: 'A'
link: (scope, element, attrs) ->
$rootScope.$on '$includeContentLoaded', (event, templateName) ->
$sections = element.find('.row > section')
for item in $sections
$section = angular.element item
$section.attr('editable','')
$section.attr('editable-type','section')
return
element.html $compile(element.contents())(scope)
]
## editable directive ##
app.directive 'editable', [()->
restrict: 'A'
link: (scope, element, attrs) ->
console.log 'editable'
]
问题是指令可编辑不起作用。