Angular version 9.1.9
typescript 3.8.3
You can add a js file under assets folder
src/assets/js/child2.js
function javaChangeCreatedBy() {
alert('Set 2 clicked');
var i_createdby = document.getElementById('inputcreatedbyid')
var i_value = document.getElementById('inputcreatedbyid').value;
}
Following html code shows the both approach one for angular click and one for html onclick.
src/app/first-component/first-component.component.html
<p>
Enter Created by:<input id='inputcreatedbyid' type="text" placeholder="Enter name" [(ngModel)]=inputcreatedby>
<button type="button" (click)="ChangeCreatedBy(inputcreatedby)">Set</button>
<button type="button" onclick="javaChangeCreatedBy()">Set 2</button>
</p>
src/app/first-component/first-component.component.ts
export class FirstComponentComponent implements OnInit {
..
createdby = 'My name';
inputcreatedby='';
ChangeCreatedBy(inputcreatedby:string){
// var inputvalue = document.getElementById("inputcreatedby").value;
this.createdby = inputcreatedby;
}
}
And finally add the script file into angular.json file
{
"projects": {
"architect": {
"build": {
..
"options": {
..
"scripts": [
"src/assets/js/child2.js"
]
}
However angular doesn't support passing type script parameter to java function.