Basic Interview Questions

  1. What is angular2 ?
  2. What are the differences between the angular1 and angular2 ?
  3. How to declare a component in angular2 ?
  4. Difference between the observer and promise .
  5. Difference between the component and directive?
  6. What is ECMA ? Note :ECMA stands for European Computer Manufacturer’s Association. Developed by Brendan Eich of netscape navigator
  7. Discuss over the ngOnInit() and the constructor()
  8. Define ActivatedRoute. Also , focus on x.params.subscribe and x.url.subscribe :   r.url.subscribe((s:UrlSegment[])
  9. How to create shared module in angular6
  10. What is template variable . How it is used ?

    <p>
    Name : <input type="text" #myInput>{{myInput.value}}
    <button (click)="go(myInput)">Show</button>
    </p>
    
    go(i){
    console.log('The data is ',i.value);
    }

    Another way :

    Through @ViewChild()  decorator

  11. What is lazy loading ?

    Lazy loading is a concept in Angular4 , in which only the module required gets loaded. Not the all modules. We can achieve lazy loading by following ways

    Step 1 : Create a module shop

Step2 : Create components like cart , checkout , confirm inside it

ng g module shop

ng g c shop/cart

ng g c shop/checkout

ng g c shop/confirm

ng g c home

Inside the app.module.ts apply following route

RouterModule.forRoot([{
path : "",
component : HomeComponent
},
{
path :"shop",
loadChildren :"./shop/shop.module#ShopModule"
}
])

Now, create shop.routing.ts inside the shop folder.

import { Routes } from '@angular/router';
import { CartComponent } from './cart/cart.component';
import { CheckoutComponent } from './checkout/checkout.component';
import { ConfirmComponent } from './confirm/confirm.component';

export const routes: Routes = [
{ path: '', component: CartComponent },
{ path: 'checkout', component: CheckoutComponent },
{ path: 'confirm', component: ConfirmComponent },
];

Use shop.routing.ts inside the app.module.ts

import { routes } from './shop.routing';
@NgModule({
declarations: [CartComponent, CheckoutComponent, ConfirmComponent],
imports: [
CommonModule,
RouterModule.forChild(routes)
]
})

Some of browsing url’s

http://localhost:4200/shop/confirm

http://localhost:4200/shop/

http://localhost:4200/shop/checkout

By Pankaj Kumar Agarwal

Leave a reply:

Your email address will not be published.