Experimenting with storing data in a model, I have created a class that looks like this:
export class Data {
constructor(moons: number, color: string) {
this.moons = moons;
this.color = color;
}
moons: number;
color: string;
}
I am importing the class using
import { Data } from './data.model';
in my Service.
Next, I declare a variable earth
of type any
.
export class DataService {
private earth: any;
constructor() {
this.earth = new Data(1, 'blue');
}
}
However, I want to set this variable to the class type Data. When I try to do so with private earth: <Data>;
, it throws an error.
The error I receive is:
10:24 - error TS1005: '(' expected.
What is the correct way to assign the class as the type?