(this is done in es5 because I like working this way)
(这是在es5中完成的,因为我喜欢这样工作)
I want to use an Angular2 component to render a div with content followed by some generated Javascript. All the non-script view template gets rendered, but the ... never is rendered.
我想使用Angular2组件来呈现带有内容的div,然后是一些生成的Javascript。所有非脚本视图模板都会被渲染,但是......永远不会被渲染。
Following is an example code:
以下是一个示例代码:
MyComponent =
ng.core.Component({
selector : 'MY-COMPONENT',
providers : [A defined provider],
})
.View({
template : `
<div id="{{contentID}}">
{{content}}
</div>
<script type="text/javascript">
alert('javascript code goes here');
</script>
`
})
.Class({
constructor : [ng.core.ElementRef, function(el) {
let retriever = new [working provider that retrieves content];
this.contentID = el.nativeElement.getAttribute('ATTRIBUTE_WITH_ID');
this.content = retriever.getContent(this.contentID);
}]
});
Everything works as expected with the exception of the Javascript not being rendered. Any help?
除了未呈现的Javascript之外,一切都按预期工作。有帮助吗?
1 个解决方案
#1
0
Angular just strips the template of <script>
tags. Use require()
to load JS scripts from your components class.
Angular只剥离
#1
0
Angular just strips the template of <script>
tags. Use require()
to load JS scripts from your components class.
Angular只剥离