Angular currently supports cancelling an event's default behavior by returning false from an event handler. Unfortunately all event handlers must pay the cost of performing this check whether they return a bool or not. In 4.0.0 we're dropping support for this feature in favor of improving performance and generating less code.
For example, currently placing the following directive on a link will prevent navigation when clicked.
import 'package:angular2/angular2.dart';
@Directive(
selector: 'inert',
host: {
'(click)': 'onClick()',
},
)
class InertDirective {
bool onClick() => false; // prevents 'click' event default behavior.
}
From 4.0.0 onward, explicit use of Event.preventDefault() will be required.
import 'dart:html';
import 'package:angular2/angular2.dart';
@Directive(
selector: 'inert',
host: {
'(click)': r'onClick($event)',
},
)
class InertDirective {
void onClick(Event event) => event.preventDefault();
}
Closed by https://github.com/dart-lang/angular2/commit/00ac8ddc37f44eed9514a2e65b4f6c0eaf0072a4. Woohoo!
Thanks @leonsenft!
Most helpful comment
Closed by https://github.com/dart-lang/angular2/commit/00ac8ddc37f44eed9514a2e65b4f6c0eaf0072a4. Woohoo!
Thanks @leonsenft!