[英]Issue on how to add jQuery into angular 2 project
嗨,我想在我的angular 2 projet中添加一些jquery代码,以动态添加输入文本字段,它的工作是有效的,但是当我单击以下代码时,removeTextField不会执行:
addTextField(){
var newTextBoxDiv = $(document.createElement('div'))
.attr("id", 'TextBoxDiv' + this.counter);
newTextBoxDiv.after().html('<label>Textbox #'+ this.counter + ' : </label>' +
'<input type="text" name="textbox' + this.counter +
'" id="textbox' + this.counter + '" value="" >'+'<span (click)="removeTextField(this.counter)" class="glyphicon glyphicon-remove pull-right" style="z-index:33;cursor: pointer"> </span>');
newTextBoxDiv.appendTo("#TextBoxesGroup");
this.counter++;
}
removeTextField(currentTextField){
alert(currentTextField);
}
任何建议,请!
这样尝试
例如,如果您输入的文本字段像
<input type="text" class="my-input-field">
在您的控制器中
$(document).click("on", ".my-input-field", ()=>{
//capture the currentTextField using jquery
this.removeTextField(currentTextField);
})
removeTextField(currentTextField){
}
示例其在角度2中实现的数据表。动态显示更新和删除按钮。
的HTML
<table class="datatable table table-striped table-bordered" (click)="onTableClick($event)"></table>
控制者
onTableClick(event){
if(event.target.className.indexOf('update-row')!= -1){ //will get the class name and check if matches update button class
this.updateRow($(event.target).attr("data-id"))
}
if(event.target.className.indexOf('delete-row')!= -1){ //will get the class name and check if matches delete button class
this.deleteRow($(event.target).attr("data-id"))
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.