this
. 我有一个按钮,我想从那里调用一个用户定义的方法
onPress
.
app.component.html
<div class="dls-menu-item" style="float: right;">
<button (click)="onPress()"></button>
</div>
<div id="comp-render">
<-----Here i want that component to be rendered
</div>
import { Component, OnInit } from '@angular/core';
@Component({
...
})
export class AnalyticsComponent implements OnInit {
constructor() {}
ngOnInit() {}
onPress() {
console.log("clicked");
document.querySelector('#comp-render').innerHTML='<object type="text/html" data="mycomp.html" ></object>';
}
}
在哪里?
mycmp.html
是:
<h1>Hello</h1>
<p>This is a custom component.</p>
<button>Click</button>
谁能告诉我怎么做吗。