I am following an Angular 2 tutorial in which an input
element is passed to a function via click event.
The tutorial has an addTodo function with this signature addTodo(event, todoText){ }
. This code is throwing up warning of Parameter 'todoText' has an implicit 'any' type.
I am wondering if there is a TypeScript object that that I can use in place of any
that represents a form input control
Example Angular 2 HTML
<div class="add-todo-form text-center">
<h1>Add ToDo</h1>
<div class="form-group">
<input class="form-control input-lg" placeholder="Add Todo.." autofocus #todoText>
<br>
<button (click)="addTodo($event, todoText)" class="btn btn-primary btn-block">Create</button>
</div>
</div>
Example Typescript
addTodo(event: any, todoText: any){
console.log('xxxxxxxxxxx');
var result: any;
var newTodo = {
text: todoText,
isCompleted: false
};
result = this._todoService.saveTodo(newTodo);
result.subscribe( (x: any)=> {
this.todos.push(newTodo);
todoText.value = '';
})
}
The answer by @Gunter was close and helped lead me to what I wanted, I was able to drill down into lib.es6.d.ts
to find HTMLInputElement
which extends HTMLElement
If it's a component or directive, then the instance of the component or directive is passed, otherwise HTMLElement
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With