Skip to main content

Posts

Showing posts from April, 2020

Why we create separate model for request and response in rest api

We take separate model for request and response these are basically from UI point of view. Suppose we get the data from end user like : firstName, lastName, email, password. We get this data in JSON formate so we have to convert this JSON object to java object for that we create a separate model object in the package ui.model.request. and it will also used by spring framework to convert JSON object to Java object. Once we persist the data then we get some response back but in that response we. have like pkId of table but we don't want to send this in our response so we can't use a single entity that we used to perisit our data. So we create a new package with ui.model.response and we will copy that required fields and this will used to convert from Java object to JSON and it will be sent back to spring framework Here incoming request like from end user Now this incoming request received by method called createUser(); and @RequestBody annotation will take t

Angular 9 ngForm, ngNoForm and Template Reference Variables

What is Angular NgForm It's simply a directive exported from FormsModule which gets automatically added to all <form> tags in your Angular templates once you import the module. Behind the curtains, the ngForm directive creates a top-level FormGroup instance and binds it to your <form> tag to enable you to work with the form. For example to access the aggregate form value or check validation status. How to Access Angular NgForm Using Template Reference Variables Since the ngForm directive is implicitly added in your <form> tag when you import its parent module (FormsModule) in your application, you don't need to do any configuration to start working with template-based forms. You can simply get a reference to your form' ngForm directive by exporting it into a local template variable and by using the ngForm directive as the value of the variable (#myForm=ngForm). Using Angular ngNoForm If you you want to import FormsModule in your application bu