angular.js - How to bind events in angularjs postLink using compile?
高洛峰
高洛峰 2017-05-15 17:04:54
0
1
575

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?

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(1)
大家讲道理

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/...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template