I'm doing an Angular exercise for an Udemy course and ran into an issue I can't solve. I'm trying to create a ClickComponent object with a unique id so each one has the next iteration (i.e. 1, 2, 3, etc). However, I'm getting the above error when I try to add parameters to the constructor to take this id from the class that is calling it. Here are the two relevant files:
app.component.ts
import { Component } from '@angular/core';
import {ClickComponent} from './click/click.component';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
display = false;
clicks = [];
toggleDisplay() {
this.clicks.push(new ClickComponent(this.clicks.length + 1));
this.display = !this.display;
}
}
click.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-click',
templateUrl: './click.component.html',
styleUrls: ['./click.component.css']
})
export class ClickComponent implements OnInit {
id;
timeStamp;
constructor(id: number) {
this.id = 0;
this.timeStamp = new Date();
}
ngOnInit() {
}
}
The error goes away if I remove the parameter from the click constructor and just set the id to 0, so it clearly has something to do with how I set up that constructor, but I don't understand what's wrong as I'm brand new to Angular. Thanks.