Curriculum
Course: AngularJS
Login

Curriculum

AngularJS

AngularJS Tutorial

0/65
Text lesson

What do I Need?

To prepare your applications for routing, you need to include the AngularJS Route module.

<script src=”https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular-route.js”></script>

Next, you must include ngRoute as a dependency in your application module.

var app = angular.module(“myApp”, [“ngRoute”]);

Your application now has access to the route module, which offers the $routeProvider.

Utilize the $routeProvider to set up various routes within your application.

app.config(function($routeProvider) {
  $routeProvider
  .when(“/”, {
    templateUrl : “main.htm”
  })
  .when(“/red”, {
    templateUrl : “red.htm”
  })
  .when(“/green”, {
    templateUrl : “green.htm”
  })
  .when(“/blue”, {
    templateUrl : “blue.htm”
  });
});

Where Does it Go?

Your application requires a container to display the content provided by the routing, which is facilitated by the ng-view directive.

There are three distinct methods to incorporate the ng-view directive into your application.

Example:

<div ng-view></div>

Example:

<ng-view></ng-view>

Example:

<div class=”ng-view”></div>

An application can have only one ng-view directive, which will serve as the placeholder for all views provided by the routing.