Jul 24, 2017 · 1 min read
If I want to send the data from a method to that html page of the component.
Please take templateUrl and then in a method send that click function html code and please tell me how to make it work.
We must send the html code through a method as shown below.
Because in my case the code will be changing based on some condition in backend and I am sending that html code through the method.
test.component.ts
-----------
import {Component} from '@angular/core';@Component({
selector: 'test',
templateUrl: `test.html`
})
export class TestComponent {
msg = "";
clickMsg = "";
nCnt: number = 0;
clickMe() {
this.nCnt = this.nCnt + 1;
this.clickMsg = "Clicked: " + this.nCnt;
}
createMsg(){
this.msg=`<button (click)="clickMe()">Click</button>
<br/> <p><strong>{{clickMsg }}</strong></p>`;
}
}test.html
----------
<div> {{ msg }} </div>
This is my requirement and am unable to get that click event.
Please try the above code and let me know.
please help me,Waiting for your working demo answers.