[英]setAttribute in Angular2 for two way data binding
I am using JavaScript API to create html elements from JSON Schema.我正在使用 JavaScript API 从 JSON Schema 创建 html 元素。 When I passed the json schema, it's returns widget html element object.当我传递 json 模式时,它返回小部件 html 元素对象。
Widget is HTML DOM object which contains tagName, id. Widget 是 HTML DOM 对象,其中包含 tagName、id。 So for two data binding I have include [(ngModel)] into dom object, for this I am using-因此,对于两个数据绑定,我将[(ngModel)] 包含到 dom 对象中,为此我正在使用 -
widget.setAttribute("[(ngModel)]", "model"); widget.setAttribute("[(ngModel)]", "model");
But It's giving me error-但它给了我错误-
[(ngModel)]' is not a valid attribute name [(ngModel)]' 不是有效的属性名称
Inside @NgModule, I have already included BrowserModule and FormsModule在@NgModule 中,我已经包含了 BrowserModule 和 FormsModule
Angular bindings and component/directive instantiation is only happening for markup added statically to a components template . Angular 绑定和组件/指令实例化只发生在静态添加到组件模板的标记中。 []
or ()
are never added to the DOM by Angular2 and Angular2 doesn't care about these being added to the DOM by other means. []
或()
永远不会被 Angular2 添加到 DOM 并且 Angular2 不关心这些是通过其他方式添加到 DOM 的。 Bindings are processed by Angular before it adds HTML to the DOM在将 HTML 添加到 DOM 之前,Angular 会处理绑定
There is a way to add/remove components dynamically to the DOM using ViewContainerRef.createComponent()
but that's it.有一种方法可以使用ViewContainerRef.createComponent()
动态地向 DOM 添加/删除组件,但仅此而已。 (for an example see Angular 2 dynamic tabs with user-click chosen components ) (示例参见Angular 2 dynamic tabs with user-click selected components )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.