我有这样的自定义指令:
<fold fold-name="Musique et sons">
<sound-button height=60 song-name="Why Make..."></sound-button>
</fold>
fold 指令有这样的模板:
<button class="fold" ng-click="showMe = !showMe">{{foldName}} ({{nb}})</button>
<div class="fold" ng-transclude ng-show="showMe"></div>
在声音按钮控制器中,我必须这样做:
$scope.$parent.$$prevSibling.$emit('foldstop')
如果我希望控制器接收事件:
$scope.$on 'foldplay', (sender, evt) ->
发生了什么:创建 3 个作用域:
<fold> Scope
<ng-transclude scope> which has no model, thus no controller.
<sound-button scope>
在 sound-button 指令中,$scope.$emit 会命中 ng-transclude 范围,它是我想要命中的范围的兄弟。
所以我使用 $scope.$parent.$prevSibling 来点击正确的控制器。它有效,但有更好的方法吗?
谢谢 !