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

873634 1719 14 859

Angular

18863 92 0 46

Wordpress

16073 72 0 36