Skip to main content

Command Palette

Search for a command to run...

Angular : Model

Updated
1 min read
Angular : Model
S

I love learning about technology and sharing that with others

introduction

model is used when we want to define custom type of the data,

here the model name is Post has three attributes two are compulsory and one is not compulsory.

export interface Post {
    title:string;
    content:string;
    id?:string;
}

``

### How to use model ?
-here we are saying that the post data is of type Post.

onCreatePost(postData: Post) { this.http.post('https://ngfirstproject-default-rtdb.asia-southeast1.firebasedatabase.app/posts.json', postData ).subscribe( responseData=> { console.log(responseData) } ) } ```

4 views

More from this blog

H

hashcodehub

271 posts

Consistent, Passionate and Organized :)