Describe how to implement routing in AngularJS.

Instruction: Explain the steps to set up basic routing in an AngularJS application.

Context: This question assesses the candidate's familiarity with the AngularJS routing mechanism, necessary for building SPA (Single Page Applications), and their ability to implement it.

Official answer available

Preview the opening of the answer, then unlock the full walkthrough.

Firstly, it is important to include the AngularJS Route module in your application. This module is not part of the AngularJS core, so you'll need to include angular-route.min.js in your HTML file and ensure that your AngularJS application module includes ngRoute as a dependency. This can be done as follows:

Include the script in your HTML: html <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.x.x/angular-route.js"></script> Add ngRoute to your module's dependencies: javascript var app = angular.module('myApp', ['ngRoute']);...

Related Questions