Angularjs指令委托不通过中间处理器射击 [英] Angularjs Directive Delegate not firing through intermediary handler
问题描述
我刚刚用了4小时试图实现与委托指令,没有运气。
使用案例:
我有一个名为过滤器。
指令当用户激活/停用滤波器父范围可能要更新屏幕上的数据。
在我让父母来说,我想对内部数据结构进行一些内部的变化,并通过与母公司通过新的过滤器的状态。
我创建了一个jsfiddel展现什么,我试图做一个简化版本。
http://jsfiddle.net/concept/zADNy/
这里是我的范围,指令
范围:{
onFilterChanged:'和;'
},
下面是中介处理程序
函数notifyParent(){
scope.onFilterChanged({过滤器:scope.filters});
}
指令委托是必须是小写(有人请纠正我,如果这说明书是错误的,如果是这样,那么为什么驼峰版本无法正常工作)
确定这样的播放和阅读并看着别人的code小时后,我发现,由于某些原因,委托函数需要小写。
下面是生成修复
http://jsfiddle.net/concept/zADNy/4/
下面是我的范围,指令
范围:{
onfilterchanged:'和;'
},
下面是中介处理程序
函数notifyParent(){
scope.onfilterchanged({过滤器:scope.filters});
}
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});
}
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});
}
这篇关于Angularjs指令委托不通过中间处理器射击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!