Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular JS routes not working, only shows path to partial, not partial

I am following a tutorial on AngularJS - "Building a website with AngularJS"

The routes I am using are pretty much the same as the tutorial :

// JavaScript Document
angular.module('quest', []).
    config(function($routeProvider) {
        $routeProvider.
            when('/about', {template:'partials/about.html'}).
            when('/start', {template:'partials/start.html'}).
            otherwise({redirectTo:'/home', template:'partials/home.html'});
    });

The problem is: it only shows the path to the resource, instead of the contents of the resource, so instead of showing the html content, it just shows:

PARTIALS/ABOUT.HTML

I am not sure what I am doing wrong, but it does work, if i go to the #/about URL it shows "PARTIALS/ABOUT.HTML" if i change the url to index.html#/start it shows "PARTIALS/START.HTML"

html of page:

<!DOCTYPE html>
<html lang="en" ng-app="quest">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <link rel="stylesheet" type="text/css" href="css/index.css" />
        <title></title>
    </head>
    <body ng-controller="MainController">
        <script type="text/javascript" src="js/angular.min.js"></script>
        <script type="text/javascript" src="js/quest.js"></script>

        <div ng-view></div>

    </body>
</html>
like image 764
nycynik Avatar asked Apr 01 '13 17:04

nycynik


People also ask

What is a route in AngularJS?

AngularJS routes enable you to create different URLs for different content in your application. AngularJS routes allow one to show multiple contents depending on which route is chosen. A route is specified in the URL after the # sign.

Why can't I navigate to 'home/child-route' in angular?

If you have configured a route like above, Angular will check, only if full path in browser URL is exactly equal to 'home' (example.com/home), then that component/module will be triggered. When you try navigating to 'home/child-route', the full path is now not matching with 'home', and this gives error.

What is the default view in Angular JS?

You can clearly see that the default view shown is the angular JS view. This is because when the page loads it goes to the ‘otherwise’ option in the $routeProvider function and loads the ‘/Angular’ view. Angular also provides the functionality to provide parameters during routing.

How to display the topics for an Angular JS course?

In our AngularJS routing example with parameters, We will present 2 links to the user, One is to display the topics for an Angular JS course, and the other is for the Node.js course. When the user clicks either link, the topics for that course will be displayed.


1 Answers

Use templateUrl instead of template

like image 90
holographic-principle Avatar answered Nov 15 '22 08:11

holographic-principle