Complete Angular Interview Guide: 1. Advantages and Disadvantages in Angular
Complete Angular Interview Guide: 1. Advantages and Disadvantages in Angular
Complete Angular Interview Guide: 1. Advantages and Disadvantages in Angular
CloudMadeEasy
Disadvantages
f. Complex
g. Less community support
7. Angular Service
A TypeScript class decorated with @Injectable()
8. Life Cycle hooks in Angular
A lifecycle hook is a call back method triggered at a specific phase of a
component instance’s lifecycle.
Constructor vs ngOnInit
>A constructor is invoked first when a class is being instantiated
>ngOnInit give us a signal that Angular has finished initialising the component
constructor – Dependency Injection
ngOnInit- Get URI parameter data, viewChild data, Call Service
9. Just-in-Time (JiT) vs Ahead-of-Time (AoT) compilation in Angular
Just-in-Time (JIT) is a type of compilation that compiles your app in the browser at
runtime.
Command :
ng build
ng serve
Ahead-of-Time (AOT) is a type of compilation that compiles our app at build time
Command :
ng build --aot
ng serve --aot
JiT AoT
Compiled in the browser. Compiled by the machine itself, via the
command line (Faster)
Each file compiled separately. All code compiled together, inlining
HTML/CSS in the scripts.
No need to build after changing your No need to deploy the compiler
code and before reloading the browser
page.
Suitable for local development. Suitable for production builds.
10. Binding in Angular
a. One-way data binding
Component :
export class TestComponent implements OnInit {
appName = "Hello Angular";
}
View :
<h1>{{appName}}</h1>
b. Event Binding
c. Attribute Binding
d. Attribute binding
<td [attr.colspan]="columnSpan">
e. Class Binding
<p [class]="myClasses">
f. Class and Style binding
g. 2 Way data binding
11.Routing
a. Routing is optional in angular
b. Wild card route / Default Route
c. {path: '', redirectTo : '/studentDetails', pathMatch : 'full'},
d. {path:'studentDetails', component : StudentDetailsComponent},
e. {path: 'studentMarks', component : StudentMarksComponent},
f. {path: "**", component : NotFoundComponent}
14. {path:'student', component : StudentComponent},
15. {path: 'studentMarks', component : StudentMarksComponent,
16. children: [
17. { path: 'Details/:id', component: StudentDetailsComponent,
18. children : [
19. { path: 'overview', component:OverviewComponent },
20. { path: 'spec', component: SpecComponent },
21. { path: '', redirectTo:'overview', pathMatch:"full" }
22. ]
23. }
24. ]
25. },
26. {path: "**", component : NotFoundComponent}
27.];
13. Lazy and Eager loading
Eager loading: To load a feature module eagerly we need to import it into
application module using imports metadata of @NgModule decorator. Eager loading
is useful in small size applications.
ngIf
<div *ngIf="false;else id_selector">
<h1>
If Part-Structural Directive
</h1>
</div>
<ng-template #id_selector>
<h1>
Else Part-Structural Directive
</h1>
</ng-template>
ngFor
array1 = ["item1", "item2", "item3", "item4"];
<div *ngFor="let item of array1">
<p > {{item}} </p>
</div>
ngSwitch
<div [ngSwitch]="'one'">
<div *ngSwitchCase="'one'">One</div>
<div *ngSwitchCase="'two'">Two</div>
<div *ngSwitchDefault>Default</div>
</div>
<form #userlogin = "ngForm" (ngSubmit) = "onClickSubmit(userlogin.value)" >
<input type = "text" name = "emailid" placeholder = "emailid" ngModel>
<br/>
<input type = "password" name = "passwd" placeholder = "passwd" ngModel>
<br/>
<input type = "submit" value = "submit">
</form>
todaydate;
componentproperty;
emailid;
formdata;
constructor(private myservice: MyserviceService) { }
ngOnInit() {
this.formdata = new FormGroup({
emailid: new FormControl("[email protected]"),
passwd: new FormControl("abcd")
});
}
onClickSubmit(data) {this.emailid = data.emailid;}
To improve overall data quality by validating user input for accuracy and
completeness.
The following classes are added to, or removed from, input fields:
<input id="name" class="form-control"
formControlName="name" required >
<div *ngIf="name.invalid && (name.dirty || name.touched)"
class="alert alert-danger">
<div *ngIf="name.errors.required">
Name is required.
</div>
<div *ngIf="name.errors.minlength">
Name must be at least 4 characters long.
</div>
</div>
Use pipes to transform strings, currency amounts, dates, and other data for
display.(We can have custom pipes)
The birthday is on
{{ birthday | date | uppercase}}