When using the custom instruction compile, how to bind events in postLink?
compile:function(tElement,tAttrs,transclude){
return {
post:function postLink(scope,iEle,iAttrs,controller){
iEle.on('click',function(){
alert(1);
}
}
}
When running, the following pops up: iEle.on is not a function
, what is the cause of this error?
大家讲道理2017-05-15 17:06:54
You wrote it wrong, there is a missing bracket when registering the click event
compile:function(tElement,tAttrs,transclude){
return {
post:function postLink(scope,iEle,iAttrs,controller){
iEle.on('click',function(){
alert(1);
}); // 这里少个小括号
}
}
https://jsfiddle.net/hjzheng/...