angularjs中阻止事件冒泡,以及指令的注意点


appModule.directive('newStr',function(){
    return{
        restrict:'AE',
        //阻止事件冒泡需要加$event参数
        template:`<div ng-click="child($event)">123</div>`,
        link:function(scope,ele,attr){
            ele.on('click',function(e){

                console.log('1')
            })
            scope.child=function($event){
                //阻止事件冒泡
                $event.stopPropagation();
                console.log('2')
            }
        }
    }
})

指令里面,<div new-Str class="new"></div>

指令newStr,在外面用的时候要new-Str这样用


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM