Angularjs Directive Delegate not firing through in

2019-08-27 23:00发布

问题:

I have just spent 4 hours trying to implement a directive with a delegate, with no luck.

Use Case:

I have a directive called "filter".

When the user activates/deactivates the filters the parent scope may want to update the data on the screen.

Before I let the parent run, i want to make some internal changes to an internal data structure and pass the new filter state through to the parent.

I have created a jsfiddel to show a simplified version of what i am trying to do.

http://jsfiddle.net/concept/zADNy/ Here is my scope in the directive

scope : {
    onFilterChanged : '&'
},

Here is the intermediary handler

function notifyParent() {
    scope.onFilterChanged({filters:scope.filters});
}

回答1:

Directive Delegates are must be lower case (someone please correct me if that statment is wrong, and if so, then why did the camel case version not work)

Ok so after hours of playing and reading and looking at other people's code, i found out that for some reason the delegate functions need to be lowercase.

Here is the resulting fix

http://jsfiddle.net/concept/zADNy/4/

Here is my scope in the directive

scope : {
    onfilterchanged : '&'
},

Here is the intermediary handler

function notifyParent() {
    scope.onfilterchanged({filters:scope.filters});
}