[SOLVED] Add user inputs?

Issue

can you add the user inputs in Angular? I am trying to display the result num + 5 in the p tag every time i change the input . Now it displays random values.

.html file

    <input #box class = "textbox" type="text" name="Name" (change)="keyup(value)>
    <p>{{value}}</p>

.ts file

@Injectable({
  providedIn: 'root'
})
@Component({
  selector: 'app-cp1',
  templateUrl: './cp1.component.html',
  styleUrls: ['./cp1.component.css']
})
export class cp1 implements OnInit {
  constructor() {}

  ngOnInit(): void {
  }

  keyup(num: number) {
    var asd = num + 5;
    this.value = asd;
  }
}

Solution

In .ts declare a variable

value:any

In .html

<input [(ngModel)]="value">
<p>{{(+value)+5}}</p>

But really I think you should take a tour of heroes. I know it spend some time, but give you a general idea of Angular

Answered By – Eliseo

Answer Checked By – Candace Johnson (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *