Search This Blog

Q66-Q70

Q66. How to implemented Security/Authentication etc in angular project?
Q67. What is the difference between two forms available in angular? Which is better? When to use which one?
Q68. How we can create a template driven form. give steps and scripting logic?
Q69. How we can create a Reactive form. Give steps and scripting logic?
Q70. How Observables are different from promises?

=========================================================================
Q66. How to implemented Security/Authentication etc in angular project?

Answer:
There are two to implement security/Authentication
1. Using Routing/Auth Guards. -- Angular #48
2. Http Interceptors -- Angular #65

=========================================================================
Q67. What is the difference between two forms available in angular? Which is better? When to use which one?

Answer:
There are two forms available in angular Template driven forms and Reactive(model- driven) forms. 

1. In a template-driven approach, most of the logic is driven from the template, whereas in reactive-driven approach, the logic resides mainly in the component or typescript code.
2. Template-driven forms are asynchronous in nature, whereas Reactive forms are mostly synchronous.
3. Template-driven forms make use of the "FormsModule", while reactive forms are based on "ReactiveFormsModule".

Reactive form can be used in the following situation
1. Complex forms with more number of fields.
2. Multiple complex validation are there. Custom validations are required
3. Require JSON structure to be send with the values in the form.
4. Good in unit testing scenarios. 

Template Driven Form : 
1. It can be used when using simple forms. Like login page. With the two way data binding. We can simply assign value to variable from ui and vice versa.
2. good for building simple forms with basic validation (required, minlength, maxlength,...).
3. Must not be used if UNIT testing is a big point. 

=========================================================================
Q68. How we can create a template driven form. give steps and scripting logic?

Answer:



=========================================================================
Q69. How we can create a Reactive form. Give steps and scripting logic?

Answer:



=========================================================================
Q70. How Observables are different from promises?

Answer:

Observables are different from Promise based response. 
(1) Observables work on multiple values time (this act as a stream of data over a network)  while Promises return only single value.  Because other variables act as a stream of data over a network we subscribe to observable while v use the then keyword in case of promises
(2) Observables are cancellable while Promises are not cancellable. When we say observables are cancellable it means we can unsubscribe observable based on conditions
(3) Observables can be manipulated using javascript functions like map, filter, reduce. 



No comments:

Post a Comment