I want to understand using the vs class interface to create a model in angular 2. When we create a model in Java or C #, we use model classes to represent the data model that runs in our application and is therefore strongly typed.
public class Movie
{
public int ID { get; set; }
public string Title { get; set; }
public DateTime ReleaseDate { get; set; }
public string Genre { get; set; }
public decimal Price { get; set; }
}
In most cases, we will adhere to data binding with this model to databases based on our requirements.
I see examples and tutorials using the same methods as this.
public class Movie
{
public int ID;
public String Title;
public Date ReleaseDate;
public String Genre;
public float Price;
}
Then I start using angular and typescript for web development. I find that some people like to use the interface to represent their model, while others like to stick to the class.
export class Movie {
public string id;
public string title;
public Date ReleaseDate;
public string Genre;
public number
}
export interface Movie {
public string id;
public string title;
public Date ReleaseDate;
public string Genre;
public number
}
However, when it comes to creating and using a model, it looks like me.
//declare
let movie = new Movie();
movie: Movie = new Movie();
movies: Movie[];
amovie: Movie;
//reactive
obsMovies: Observable<Movie[]>;
obsAMovie: Observable<Movie>;
, typescript. - , , , .