简体   繁体   中英

Angular 2+ add dynamically html text on div with “onChange” function

I've developed an app that dynamically changes the HTML text in a div element as soon as the value in the select element changes.

In HTML:

<div id="update"></div>

In Typescript:

$('#update').html(`<input type="file" (change)="onFileChanged($event)">`

It works. When I select a file, the function is not called.

Try this;

var html = $compile('<input type="file" (change)="onFileChanged($event)"')($scope);
 $('#update').html(html);

Remove jquery code and set a flag for a div. When user click on button the flag should be change. according to flag status you can set your text.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM