0

I am trying to add values entered in the input tag to an array using (click)="add(data), I was following a tutorial from the "https://www.freecodecamp.org/news/learn-how-to-create-your-first-angular-app-in-20-min-146201d9b5a7/" but the way they are doing is the same I have done but it is showing errors. I think it is due to the update, if there is anything I am doing wrong or left something then do guide me. `

<div class="container">
  <form>
    <div class='form-group'>
      <h1 class = "text-center text-primary">Todo App</h1>
      <div class = "input-group-prepend">
        <input type="text" #data class = "form-control" placeholder="Add Todo" name="todo" >
        <span class="input-group-text" (click)="add(data)">Add</span>
      </div>
    </div>
  </form>
</div> 
<div class='data'>
<ul class = 'list-instyled'>
  <li *ngFor = "let todo of list">{{todo}}</li>

</ul>
</div>

and the app component.ts file is

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'Todo-app';
  list=[];
  add(data){
    this.list.push(data);
    console.log(this.list);
  }

}

` the error which I am getting is

Error: src/app/app.component.ts:11:7 - error TS7006: Parameter 'data' implicitly has an 'any' type.

11   add(data){
         ~~~~


Error: src/app/app.component.ts:12:20 - error TS2345: Argument of type 'any' is not assignable to parameter of type 'never'.

12     this.list.push(data);
                      ~~~~

I am new to the angular tried to build the todo app. if anyone finds the solution, then please help.

VLAZ
  • 26,331
  • 9
  • 49
  • 67
  • 1
    You've not given your `list` a type, so it's inferred as an array of `never`. – VLAZ Jun 02 '21 at 17:14
  • 1
    Just add type to your list list: Array= []; or list: string[] = [] – Shashi Kiran Jun 02 '21 at 17:18
  • thanks for the clarification..but now the current problem is pushing input value to the array. `export class AppComponent { title = 'Todo-app'; list:string[]=[]; add(data){ this.list.push(data); console.log(this.list); } }` Parameter 'data' implicitly has an 'any' type. 11 add(data){ – abheet kumar Jun 03 '21 at 12:56

0 Answers0