Angularjs Directive Delegate not firing through intermediary handler

余生长醉 提交于 2019-12-13 06:19:35

问题


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});
}


来源:https://stackoverflow.com/questions/15344297/angularjs-directive-delegate-not-firing-through-intermediary-handler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!