Angular: RFC: Event handler return value will be ignored in 4.0.0

Created on 16 May 2017  路  1Comment  路  Source: angulardart/angular

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();
}

Most helpful comment

>All comments

Was this page helpful?
0 / 5 - 0 ratings