Interview Questions

1. Can you demonstrate navigation between different routes in an Angular application?

You can demonstrate the navigation between different routes in an Angular app in the following way. See the following code to demonstrate navigation in an Angular app named "My First App."

import from "@angular/router";  

.  

.  

.  

@Component({  

  selector: 'app-header',  

  template: `  

<nav class="navbar navbar-light bg-faded">  

  <a class="navbar-brand" (click)="goHome()">My First App</a>   

  <ul class="nav navbar-nav">  

    <li class="nav-item">  

      <a class="nav-link" (click)="goHome()">Home</a>   

    </li>  

    <li class="nav-item">  

      <a class="nav-link" (click)="goSearch()">Search</a>   

    </li>  

  </ul>  

</nav>  

})  

class HeaderComponent {  

  constructor(private router: Router) {}   

  goHome() {  

    this.router.navigate(['']);   

  }  

  goSearch() {  

    this.router.navigate(['search']);   

  }  

}  


By Md Riyazuddin 2 0
Is this helpful? Yes No

Submit an interview question

Submitted questions and answers are subject to review and editing, and may or may not be selected for posting, at the sole discretion of w3Sniff.

Get Started

Comments

Leave a Comment


Check out more interview questions

Based on your skills

MS SQL Server

1684449 1720 23 859

Angular

43439 92 0 46

Wordpress

35123 72 1 36