【发布时间】:2016-07-27 12:02:35
【问题描述】:
在 firefox 中,您必须传入事件才能使以下操作生效
// In directive link
function linkFunc(scope, element, attr){
element.on('click', function(event){
event.stopPropagation();
scope.myVar.value = false;
scope.$digest();
});
]
在 Chrome 中,您可以执行以下操作
// In directive link
function linkFunc(scope, element, attr){
// Won't work for firefox
// will run into ReferenceError: event is not defined
element.on('click', function(){
event.stopPropagation();
scope.myVar.value = false;
scope.$digest();
});
}
这种行为差异背后的原因是什么?
【问题讨论】:
-
您从哪里获取
$event? -
1) 你确定你在写角度吗? 2)
$event可能是未定义的,这将引发ReferenceError异常。 -
对不起,我错过了输入
$,但是 chrome 中的 Angular 工作没有明确传入的事件。代码在 Angular 的指令链接中 -
你使用 ng-click 按钮?
-
@AlainIb 它在指令链接函数中,所以它已经引用了元素
标签: javascript angularjs google-chrome firefox