[英]How to pass an object in typescript to HTML string without angular $compile
This is an angular program, but a package we wrote is in typescript. 这是一个有角度的程序,但我们编写的程序包使用打字稿。 Basically what I am trying to solve is how do I make 'this' go into the HTML string as a real angular bound object.
基本上,我想解决的是如何使“ this”作为真正的角度绑定对象进入HTML字符串。 I can't use $compile because this is a typescript file.
我不能使用$ compile,因为这是一个打字稿文件。 Any help is appreciated.
任何帮助表示赞赏。 Currently I can only pass pieces of the object as strings, like this.name.
目前,我只能将对象片段作为字符串传递,例如this.name。
export class GroupView extends ObjView {
name: string = "GroupView";
constructor(parentView: GroupView, protected group: Group) {
super(parentView, group)
if(group){
this.name = group.name
this.structureItem = '<custom-directive this-model="' + this + '" name="' + this.name + '"></custom-directive>';
}
}
}
Once the this.structureItem is added to the page, I need to be able to access this-model by reference... the actual object not a copy of it. 将this.structureItem添加到页面后,我需要能够通过引用访问此模型...实际对象不是它的副本。
I'd suggest another approach. 我建议另一种方法。 Use the
ng-if
-directive in the HTML-template. 在HTML模板中使用
ng-if
-directive。 For example: 例如:
TS TS
constructor(parentView: GroupView, protected group: Group) {
super(parentView, group)
if(group){
this.name = group.name;
}
}
HTML HTML
<custom-directive ng-if="group" name="name"></custom-directive>
This way the element will only be visible when group
is valid. 这样,只有在
group
有效时该元素才可见。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.