What's the difference between establishing a class and an interface in angular?

What"s the difference between creating a class and an interface in

angular? What"s the difference between
defining variables in constructor?

export class Hero {
id: number;
name: string;
}

export class Hero {
constructor (

)
public id: number,
public name: string) { }

}

Thank you

Feb.26,2021

interface Person {
    name: string;
    age: number;
}

class Zhangsan implements Person {

}

class Zhangsan {
    name: string;
    age: number;
}

probably means that interface extracts public properties and methods, and class is a specific object


interface just provides a declaration describing what your object looks like, and cannot instantiate
class is to describe what your object looks like

constructor(

public id: number,
public name: string) { }

automatically declares class properties id and name, and automatically assigns values in the constructor


interface is the interface used to standardize class


the class, used by the official demo is supposed to use interface, right? What is particular about

Menu