html - Dart Web中的onClick事件

标签 html dart dart-html

我是Dart-Web的初学者。我试图通过dart处理HTML DOM中的单击事件,但似乎不起作用。在它下面是我当前的代码。

<div>
   <button type="button" onclick="(onclick)=clickHandle()">Sign-in</button>
</div>


@Component(
 selector: 'todo-list',
 styleUrls: ['login_component.css'],
 templateUrl: 'login_component.html',
 directives: [
  MaterialButtonComponent,
  MaterialCheckboxComponent,
  MaterialFabComponent,
  MaterialIconComponent,
  materialInputDirectives,
  materialInputDirectives,
  NgFor,
  NgIf,
 ],
 providers: [ClassProvider(LoginService)],
 )
 class LoginComponent implements OnInit {
  final LoginService loginService;

  List<String> items = [];
  String newTodo = '';

  LoginComponent(this.loginService);

  @override
  Future<Null> ngOnInit() async {
  items = await loginService.getTodoList();
  }

  void add() {
  items.add(newTodo);
  newTodo = '';
  }

  void clickHandle() {
  print("Button Clicked");
  }

  String remove(int index) => items.removeAt(index);
  }

请请求任何其他文件来回答问题。

最佳答案

onclick="(onclick)=clickHandle()"

是错的。

它应该是
(click)="clickHandle()"

事件是clickonClick只是一个属性,您可以在其中注册发生该click事件时要调用的处理函数,但是Angular会为您在onClick中注册该处理函数。

关于html - Dart Web中的onClick事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53802695/

相关文章:

java - 在 android web View 中,html 页面被视为在大屏幕而不是在移动设备中打开

dictionary - Dart Map.remove哪里没有删除所有符合删除条件的键

当我需要将文件名放入变量时,Flutter 如何删除文件扩展名

dart - 如何进行精确的十进制计算?

dart - Dart 中的工作音频循环示例

dart - 使用 Dart lang 为 "pseudo-element"设置样式

javascript - 网页向右滚动,宽度无限扩展

javascript - 单击时出现奇怪的链接行为

dart - 如何在Dart中更改按钮的单击事件

javascript - 如何禁用 JavaScript 中的 href 链接?