"#" と、@ViewChild を利用の仕方を覚えた!!
https://github.com/firefirestyle/ebook_windstyle_markdown/tree/master/angular/tiny-markdown
import 'package:angular2/platform/browser.dart'; import 'package:angular2/core.dart'; import 'dart:async'; import 'dart:html' as html; import 'package:markdown/markdown.dart' as mark; main() { bootstrap(AppComponent); } @Component( selector: 'markdown-component', template: """ <div #markdowncontent></div> """, ) class MarkdownComponent implements OnInit { @Input() String content; html.Element _contentElement; @ViewChild('markdowncontent') set main(ElementRef elementRef) { _contentElement = elementRef.nativeElement; } ngOnInit() { _contentElement.children.clear(); _contentElement.children.add(new html.Element.html( """<div>${mark.markdownToHtml(content)}</div>""", treeSanitizer: html.NodeTreeSanitizer.trusted) ); print(">> ${content}"); } } @Component( selector: 'my-app', directives: const [MarkdownComponent], template: """ <markdown-component [content]='content'></markdown-component> """ ) class AppComponent { String content = """ # H1 aasasdfa;lklasdf """; }
0 件のコメント:
コメントを投稿