Angular 2 - 在firefox上使用$ event.srcElement的问题

时间:2016-05-16 15:10:54

标签: angular

我的代码的很多部分都使用了@ event.srcElement,例如......

<label><input (change)="setCompare($event.srcElement.checked,item.id, item.name, item.capacity, item.photoId,item.occupiers[0])" type="checkbox">Compare availability</label>

在Chrome上运行良好,但使用FF会抛出:

错误:

  

EXCEPTION:app / templates / results.html中的错误:35:22原文   EXCEPTION:TypeError:event.srcElement未定义ORIGINAL   堆栈跟踪:   ResultsComponent.prototype.onScroll@http://localhost:3002/app/components/results/results.component.js:124:9   anonymous/_View_ResultsComponent0.prototype._handle_scroll_13_0@ResultsComponent.template.js:268:15   DebugAppView.prototype.eventHandler /&LT; @ http://localhost:3002/node_modules/@angular/core/src/linker/view.js:316:24   decoratePreventDefault /&LT; @ http://localhost:3002/node_modules/@angular/platform-browser/src/dom/dom_renderer.js:278:36   DomEventsPlugin.prototype.addEventListener / outsideHandler /&LT; @ http://localhost:3002/node_modules/@angular/platform-browser/src/dom/events/dom_events.js:20:93   Zonehttp://本地主机:3002 / node_modules / zone.js / DIST / zone.js:323:20   NgZoneImpl / this.inner&LT; .onInvoke @ http://localhost:3002/node_modules/@angular/core/src/zone/ng_zone_impl.js:45:32   Zonehttp://本地主机:3002 / node_modules / zone.js / DIST / zone.js:322:20   Zonehttp://本地主机:3002 / node_modules / zone.js / DIST / zone.js:230:29   NgZoneImpl.prototype.runInnerGuarded@http://localhost:3002/node_modules/@angular/core/src/zone/ng_zone_impl.js:78:67   NgZone.prototype.runGuarded@http://localhost:3002/node_modules/@angular/core/src/zone/ng_zone.js:228:58   DomEventsPlugin.prototype.addEventListener/outsideHandler@http://localhost:3002/node_modules/@angular/platform-browser/src/dom/events/dom_events.js:20:56   Zonehttp://本地主机:3002 / node_modules / zone.js / DIST / zone.js:356:24   Zonehttp://本地主机:3002 / node_modules / zone.js / DIST / zone.js:256:29   ZoneTask / this.invoke @ http://localhost:3002/node_modules/zone.js/dist/zone.js:423:29

有关如何修复它的任何建议 - 或者:用更多浏览器不可知的内容替换$ event.srcElemento?

1 个答案:

答案 0 :(得分:10)

您可以使用target代替srcElement

$event.target.checked

另见https://developer.mozilla.org/en/docs/Web/API/Event/srcElement

相关问题