I need to combine the results of the select / option in a variable (it belongs to the URL of an API) and I am new handling Typescrip, then I get several errors and other things that I don't know how to do. For example, add the results of select / option (url next to cat, diff, type) and then save it in a localStorage to call it to another component (as it did in javascript)
html
<h5>Select Type:</h5>
<form name="formul2" class="cont">
<div class="box">
<select id="type" name="type" [(ngModel)]="typ">
<option value="">Any Type</option>
<option value="&type=multiple">Multple Choice</option>
<option value="&type=boolean">True / False</option>
</select>
</div>
</form>
<a class="btn" id="fetch" href="game">Play</a>
<a class="btn" href="highscores">High Scores</a>
TS
export class IndexComponent implements OnInit {
constructor() { }
ngOnInit() {
}
public diff:string;
public cat:string;
public typ:string;
}
const url:string = 'https://opentdb.com/api.php?amount=20';
var newUrl:string = url + diff + cat + typ;
var x = document.getElementById('fetch')
x.addEventListener('click', function(e) {
localStorage.setItem("urlGame", newUrl);
});
url,newUrl,xcan't just dangle around somewhere - you need to place them within your class. 2.x.addEventListener(...)needs to be wrapped in a method. 3. Read up about forms in angular, thereby on submit of the form you can retrieve the desired values of the form elements and process them according to your requirement.