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这样用