Currently, I am working through an Angular 2 tutorial where an input
element is being passed to a function through a click event.
The tutorial includes an addTodo function with the following signature: addTodo(event, todoText){ }
. However, there is a warning stating that Parameter 'todoText' has an implicit 'any' type.
I am contemplating if there exists a TypeScript object that can be used instead of any
specifically meant to represent 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 = '';
})
}