When calling notify
you need to specify the argument in a slightly different way:
$scope.notify( { facet: 'someFacetGroup' } );
Frage
What the heck is going on here?
I'm trying to call a function defined on a parent scope's controller through a child directive. For some reason '&' is failing me?
The controller's html:
<div ng-controller="facetCtrl">
<header>
<div facet></div>
<div facet></div>
</header>
</div>
The facet directive's html:
<div ng-click="selectFacet($event)" notify="facetGroupSelected(facet)">
<div>{{ name }}</div>
</div>
The controller's coffee:
app = angular.module 'myApp', []
class facetCtrl
constructor: (@$scope) ->
@$scope[fn] = @[fn] for fn in [
'facetGroupSelected'
]
facetGroupSelected: (facetGroup) =>
console.log(facetGroup)
app.controller 'facetCtrl', [
'$http'
facetCtrl'
]
The directive's coffee:
app = angular.module 'myApp'
facetDirective = ->
replace: true
restrict: 'A'
templateUrl: '..path/to/template'
scope:
notify: '&'
link: (scope, element, attrs) ->
scope.selectFacet = ($event) ->
scope.notify('someFacetGroup')
app.directive 'facet', [
'facetDirective'
]
Somewhere along the line, however, my function arguments are getting dropped. The function call from the directive triggers the parent controller's function, but like I said, the arguments don't make it. Are coffee scopes (__bind.apply
, etc) breaking something?
Lösung
When calling notify
you need to specify the argument in a slightly different way:
$scope.notify( { facet: 'someFacetGroup' } );