Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将dart与dart:html一起使用_Dart_Angular Dart_Dart Html - Fatal编程技术网

将dart与dart:html一起使用

将dart与dart:html一起使用,dart,angular-dart,dart-html,Dart,Angular Dart,Dart Html,是否可以将默认省道库html与角省道一起使用? 即: 如何避免在不使用任何计时器的情况下获取“null”按钮 基本上,我只在路由中使用angular,但我想继续使用dart:html来控制DOM和事件。是的,您可以这样做,但这通常不是一个好主意 使用@ViewChild(…)或类似的角度方法来获取对组件视图中元素的引用 <button #myButton>click me</button> 点击我 @ViewChildren('myButton')) 设置我的按钮(列

是否可以将默认省道库
html
与角省道一起使用? 即:

如何避免在不使用任何计时器的情况下获取“null”按钮


基本上,我只在路由中使用angular,但我想继续使用
dart:html
来控制DOM和事件。

是的,您可以这样做,但这通常不是一个好主意

使用
@ViewChild(…)
或类似的角度方法来获取对组件视图中元素的引用

<button #myButton>click me</button>
点击我
@ViewChildren('myButton'))
设置我的按钮(列表值){
if(value.isNotEmpty){
打印(值优先);
}
}
如果只想使用添加单击处理程序

<button (click)="onClick">click me</button>
点击我
这可能是更好的方法,但听起来您以某种方式动态添加按钮,并且以声明方式添加单击处理程序在这种情况下可能不起作用(需要更多信息)

编辑: 如果像我这样的人想使用dart:html而不是ng代码,那么可以使用它

import 'package:angular/angular.dart';
import 'dart:html';

// AngularDart info: https://webdev.dartlang.org/angular
// Components info: https://webdev.dartlang.org/components

@Component(
  selector: 'container',
  template: '<h1>Test 1</h1><button #test1>Bottone test 1</button>',
)
class Test1Component implements OnInit{

  @ViewChild('test1')
  ButtonElement button;


  @override
  void ngOnInit() {
    //Verified that button is initialized
    print(button);
    //Initialize click
    button.onClick.listen((e) => print("Clicked"));
  }
}
导入“包:角度/角度.dart”;
导入“dart:html”;
//角镖信息:https://webdev.dartlang.org/angular
//组件信息:https://webdev.dartlang.org/components
@组成部分(
选择器:'容器',
模板:“测试1底部测试1”,
)
类Test1Component实现OnInit{
@ViewChild('test1')
按钮元件按钮;
@凌驾
void ngOnInit(){
//确认按钮已初始化
打印(按钮);
//初始化单击
button.onClick.listen((e)=>打印(“单击”);
}
}

在页面中添加元素后是否立即调用任何事件?没有特定事件。这取决于您如何添加它以及使用什么方法。您可以使用
@ViewChildren(…)set buttonQuery(…){…}
。这样,在添加/删除元素时将调用setter。对于其他场景还有其他方法。在这种情况下,您可以静态添加
,只需在初始化时添加单击处理程序,以后不要使用声明性语法将其删除,应该使用
。避免使用类似于本答案的程序代码。
<button (click)="onClick">click me</button>
import 'package:angular/angular.dart';
import 'dart:html';

// AngularDart info: https://webdev.dartlang.org/angular
// Components info: https://webdev.dartlang.org/components

@Component(
  selector: 'container',
  template: '<h1>Test 1</h1><button #test1>Bottone test 1</button>',
)
class Test1Component implements OnInit{

  @ViewChild('test1')
  ButtonElement button;


  @override
  void ngOnInit() {
    //Verified that button is initialized
    print(button);
    //Initialize click
    button.onClick.listen((e) => print("Clicked"));
  }
}