Input onchange with Angular2

2019-07-26 21:48发布

问题:

I try to detect on change with dart. Example html:

<div>
    <input id="photoUpload" type="file" name="photo" (onchange)="update()" multiple>
</div>

Dart:

@Component(
    selector: "photo-upload-dialog", templateUrl: "photo_upload_dialog.html")
class PhotoUploadDialog {


  update() async {
    print('Changed!');
  }
}

But nothing in a console.

回答1:

onChange is the default event handler name, not the event name.

Use instead

(change)="update()"