Khizar Iqbal Khizar Iqbal - 1 year ago 43
AngularJS Question

templateUrl is not being called by angular $routeProvider

I am learning AngularJs now a days and stuck in the error and couldn't resolve it for the last two days. First let's look at my code first:


<!DOCTYPE html>
<title>Learn Angular Js - Scott Allen</title>
<meta charset="utf-8" />

<body ng-app="LearnAngular">
<h1>Git Hub Viwer</h1>
<div ng-view></div>

<script src="angular.js"></script>
<script src="angular-route.js"></script>
<script src="App.js"></script>
<script src="MainController.js"></script>


(function () {
var app = angular.module("LearnAngular", ["ngRoute"]);

app.config(function routeConfig($routeProvider) {
.when("/main", {
templateUrl: function () {
return "Main.html";
controller: "MainController"
.otherwise({ redirectTo: "/mian" });


(function () {
var MainController = function ($scope, $interval, $location) {
alert("var MainController = function ($scope, $interval, $location) {};");

var decrementCountdown = function () {
$scope.countdown -= 1;
if ($scope.countdown < 1) {

var countDownPromise = null;
var startCountdown = function () {
countDownPromise = $interval(decrementCountdown, 1000, $scope.countdown);

$ = function (username) {
if (countDownPromise) {
$scope.countdown = null;

// redirect to the url.

$scope.username = "angular";
$scope.countdown = 5;

var app = angular.module("LearnAngular");
app.controller("MainController", MainController);



<form name="searchUser" ng-submit="search(username)">
<input type="search" required placeholder="Enter username to search" ng-model="username" />
<input type="submit" value="Search" />

When I run the application, i see this url:


which shows that I successfully redirect to the main route but
is not being shown on the
page and browser is not requesting for the
when I examine the network of browser.

Here is the screen shot of my application:
Screen Shot of my application.

I searched on the internet and tried many solutions but none of them solves my problem. I don't what is wrong with the code. I am developing in

Thanks in advance for your help and time.

Answer Source

You had typo in URL there in otherwise's redirectTo value, it should be /main

.otherwise({ redirectTo: "/main" });