简体   繁体   English

在Dart中如何使用setInnerHtml元素 <template> 标签?

[英]In Dart how to setInnerHtml elements with <template> tag?

For example, I have a piece of code like this: 例如,我有一段这样的代码:

String_test="
<template>
<label> {{count2}}  SSSSSSSSSSSSSSSSSSSSSSSSS </label> 
<input id="input1" type='text' value='{{count2}}'>
</template>"

and I want to assign String_test to another element, like: 我想将String_test分配给另一个元素,例如:

DivElement span2 = new Element.tag("div");
span2.setInnerHtml(String_test);
_content.nodes.add(span2);

However, the "< template >' tag is not recognized, nothing will show up. 但是,无法识别“ <template>”标记,不会显示任何内容。

NOTE: My purpose is to use setInnerHtml to dynamically add contents to the webpage with data-binding still OK. 注意:我的目的是使用setInnerHtml在数据绑定仍然可以的情况下将内容动态添加到网页。

Any ideas? 有任何想法吗?

Thanks! 谢谢!

It appears that you are including raw html in your Dart program files. 看来您在Dart程序文件中包含原始html。 This is not how Dart works. 这不是Dart的工作方式。 Dart has code (kept in .dart files) that is referenced to via a tag in the HTML file. Dart具有通过HTML文件中的标记引用的代码(保存在.dart文件中)。 This very quick tutorial will show you how to do that: https://www.dartlang.org/docs/tutorials/connect-dart-html/ 这个非常快速的教程将向您展示如何做到这一点: https : //www.dartlang.org/docs/tutorials/connect-dart-html/

Templating is found in the Dart Polymer library. 在Dart Polymer库中可以找到模板。 It is too long of a process to go into here but you can find a short tutorial at: https://www.dartlang.org/docs/tutorials/polymer-intro/ 进入此处的过程太长了,但是您可以在以下网址找到一个简短的教程: https : //www.dartlang.org/docs/tutorials/polymer-intro/

I would also mention that Angular comes in a Dart flavor and I find it more accessible than the Polymer libraries. 我还要提到Angular具有Dart风格,我发现它比Polymer库更易于访问。 The tutorials and documentation are also much better. 教程和文档也更好。 Angular is a more comprehensive suite of libraries and it's tutorials can be found here: https://github.com/angular/angular.dart.tutorial/wiki Angular是一套更全面的库,可以在这里找到其教程: https : //github.com/angular/angular.dart.tutorial/wiki

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM