[英]How to append html from typescript file and perform functionality on it in angular2
I am working on angular2 application. 我正在研究angular2应用程序。
I am getting one issue when I am appending date field from typescript the field was generated and looking perfect but the functionality I have performed on field click was not working(date picker will open on click on field and event icon). 我从打字稿中追加日期字段时遇到一个问题,该字段已生成并且看上去很完美,但是我在字段单击上执行的功能不起作用(日期选择器将在单击字段和事件图标时打开)。
HTML 的HTML
<div id="specific_dates_container" class="field_area">
</div>
TYPESCRIPT 打字稿
let count = document.querySelectorAll('.specific-date').length;
count += 1;
this.addCouponForm.addControl('specific_date'+count, new FormControl());
let html = "<div class='specific-date' id='specific_date"+count+"'><input placeholder='MM/DD/YYYY' ngx-mydatepicker [options]='calendarOptions' #sd"+count+"='ngx-mydatepicker' formControlName = 'specific_date"+count+"' (click)='sd"+count+".toggleCalendar()' readonly><i class='material-icons' (click)='sd"+count+".toggleCalendar()'>event</i></div><br>";
$("#specific_dates_container").append(html);
You need to change your approach towards this 您需要为此改变方法
It seems you are tying to create controls dynamically To do that you need to follow this link 看来您想动态创建控件,为此,您需要点击此链接
How to dynamically add and remove form fields in Angular 2 如何在Angular 2中动态添加和删除表单字段
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.