Day 14 : Concepts in Angular
We have studied the angular directives in previous blog.....Now we are going to learn the concepts in angular.....
ngModel :
- The ngModel directive binds select, input and form control.
- The ngModel try to bind to the property given by evaluating the expression on given scope.
- If the property doesn't exist on scope, it will be created and added to the scope.
- One-way binding syntax - [ngModel]=" " it binds to input.value.
- Two-way binding syntax - [(ngModel)]=" " it update with value of input.value.
- The two-way binding syntax is compound from [ngModel]=" " and (ngModel)=" ".
- Binds the view into the model, which other directives require.
- Providing validating behavior(i.e email,url)
- Setting related css classes like ng-valid, ng-invalid, ng-empty etc.
Directives:
There are three kinds of directives in angular :
- Components : directives with template.
- Structural directives : change the structure of the view. Eg. NgFor and NgIf
- Attribute directives : change the behavior or style of an element, component or another directive.
Two-way Binding :
- The two-way binding is a combination of square brackets and parenthesis as[( )].
- Where the square brackets[] are of property binding with the parenthesis() of event binding.
- The two-way binding is used to listen the events and update values simultaneously between parent and child.
- Two-way binding combines property binding and event binding with inputs & outputs, where property binding sets a specific element property and event building listens for an element change event.
Components :
- Components are the most basic user interface building block of angular app.
- The components are subset of directives and associated with template.
- The component must belong to or must member of NgModule.
- The @Component decorator identifies the class as component class and specifies the metadata.
"The decorator mark a class as angular component and provides configuration metadata that determines how the component should be processed and used at runtime."
ngFor :
- The ngFor directive is used to repeat a portion of HTML template once per each item from list.
- The ngFor is a structural directive same as ngRepeat.
- Syntax ----- *ngFor = "let item of items;" where the item is object and items is class.
Declarative vs Imperative :
- The declarative specify what to do but not how to do it.
- The declarative is a functional OOP.
- The imperative specify both what and how to do it.
- The imperative is a procedural OOP.
- Most of the developers and angular also prefer declarative over imperative programming.
- In declarative programming we write code that describes what you want, but not necessarily how to get it.
- The how to get it is solved by imperative codes.
If you have any doubts comment below and for more understanding watch below video :
Thank You!!!
Comments
Post a Comment