简体   繁体   English

如何从Typescript文件附加HTML并在angular2中对其执行功能

[英]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.

相关问题 Angular2-如何从打字稿中获取变量到我的HTML dom - Angular2 - how to get a variable from typescript to my html dom 如何从CSS或HTML文件中的变量附加CSS? 角4+ - How to append CSS from a variable in CSS or HTML file? Angular 4+ 对于Angular2项目,我如何连接从typescript生成的所有JavaScript文件并将它们添加到我的index.html文件中 - For Angular2 project, In gulp how do I concat all my JavaScript files that were generated from typescript and add them to my index.html file angular2(typescript)从另一个文件导出变量 - angular2(typescript) export variables from another file 如何从Javascript回调方法中调用Typescript方法-Angular2 - How to call Typescript method from Javascript callback method - Angular2 如何在没有 HTTP 的情况下从 Angular2 (TypeScript) 中的 json 获取数据? - How to fetch data from json in Angular2 (TypeScript) without HTTP? 如何在一个index.html文件中加载来自不同文件夹的多个angular2组件? - How to Load multiple angular2 components from different folders in one index.html file? Angular2:克隆组件/HTML 元素及其功能 - Angular2: Cloning component / HTML element and it's functionality Angular 9 如何使用 TypeScript 将 HTML 文件作为字符串导入? - Angular 9 How to import HTML file as a string with TypeScript? 如何在我的模板(Angular2 / TypeScript)中将HTML字符串转换为HTML? - How can I convert strings of HTML into HTML in my template (Angular2/TypeScript)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM