Dart2js& #39;的输出导致“null不是对象”

dart2js's output causes "null is not an object"

本文关键字:null 对象 输出 Dart2js      更新时间:2023-09-26

运行后

private/dart/dart-sdk/bin/dart2js -m -o public/js/script.js private/dart/script.dart

结果javascript返回

TypeError: 'null' is not an object (evaluating 'J.RE(a).gVs')

然而,未被最小化的错误是

TypeError: 'null' is not an object (evaluating 'J.getInterceptor$x(receiver).get$onBlur')

这可能更有意义。

无论我使用script.js还是script.compiled.js,它都会这样做。

省道代码是

import 'dart:html';
import 'dart:core';
void main() {
   querySelector("#authorInput").onBlur.listen(updateSurname);
}
void updateSurname(Event e){
   String author = (e.target as InputElement).value;
   String surname = author.split(' ').last;
   querySelector("#surnameInput").text = surname;
}

  .form-group
     %label(for="authorInput") Author
     %input.form-control#authorInput(type="text" name="author" placeholder="Enter author")
  .form-group
     %label(for="surnameInput") Surname
     %input.form-control#surnameInput(type="text" name="surname" placeholder="Enter surname")

我相信它应该这样工作,尽管情况显然不是这样。

我明白了

我将编译好的javascript文件包含在html页面的标签中。把它移到身体的最底部,就能解决一切问题。