Angular Notes
Angular Notes
Transfering of data from .ts file to DOM only is known as one way data binding.
By using String Interpolation we can access any property value defined in .ts file to DOM.
Case1--
Case2--
Case3--
we cant use assignment operator inside the {{ }} i.e. we cant assign value from DOM.
Case4--
By using property binding we can assign or provide value to html attribute like value
attribute..
in above example after clicking on buttton,Test() method get executed after clicked.
value = 555;
Test(){
console.log(this.value);
Transfering of data from .ts file to DOM and DOM to .ts file is known as two way data
binding.
we use [(ngModel)] directive for two way data binding available in forms module and
forms module available
Test(){
console.log(this.twowaydatabinding);
}
Routing >>
Routing in Angular allows the users to create a single-page application with multiple views
and allows navigation between them.
Simple Routing --
1) By using selector -
In this case we copy the selector from .ts file and paste it into the .html file,depends ont the
position where its
Example --
suppose we have created login component,when we entered into .ts file we get selector as
Selector : app-login,
now we have to just copy that "app-login" selector and paste it into the .html file in "<>".
as--
<app-login><app-login>
Now the code available in login component will get executed once current file execution is
done.
2) After that we will set path routing.module.ts file by using path and component as key
with values.
3) In last step we have to use anchor tag with routerLink to provide path to the routerLink
that just we defined in the routing.module
But in this case when we have lots of componet are there like more 50 then we should not
prefer this routing as our application
To avoid freezed effect, lazy loading concept back into the picture-
Lazy Loading--
The main purpose of lazy loading is to avoid the slowness of application now question
comes to our mind that how?
>> the simple way is to create new module in that new module we again create some
component,directives and pipes.
ng g m name --routing
Example --
Step 1) Create Module -- ng g m admin --routing
2) ng g c adminsignup
Step 3) we have create path in root routing.module.ts as we created new module but to
access that module form current we have to increase
the scope of current module for that we create path inside the "routing.module.ts" as -
{path:'admin'
loadchildren:()=>import('./admin/admin.module').then(mod=>mod.AdminModul)}
<!-- <a href="login">Click here for login</a> //when we use href for routing it will refresh
<router-outlet></router-outlet>
In short it helps to display component that we are define in the routing.module.ts "path",on
the screen.
Example--
<router-outlet></router-outlet>
By using global component "home" we can also redirect to the admin module as--
4) Create button or anchor tag inside the home which directing towards admin module as
>>
<router-outlet> inside the home.html else it may not get directed to the admin module.