2

I have a partial web page called home.html. When I run the page in chrome, the address shows me http://127.0.0.1:63342/Angular-01/htmlPage1.html?_ijt=vfdcblvb6ahn0t6et7rv6k8tm0#/home where as I should see a cleaner url (without the extension). I have configured my route as:

var myApp = angular.module("myModule", ["ngRoute"])
    .config(function ($routeProvider) {
        $routeProvider
            .when("/home", {
                templateUrl: "views/home.html",
                controller: "homeController"
            })
    })
    .controller("homeController", function ($scope) {
        $scope.message = "Home page";
    })

How do I achieve it?

1 Answer 1

2

When using angular routing you don't need to call a static page as you are doing home.html. you simply run your app and say you want to go home and angular routing will take you to home.html

When I run the page in chrome? If you open only a static html page in browser it will serve you only that page not the angular application

In order to run whole angular app

If you are running your app with http-server or any other node server you need to server the whole angular app and then index.html will be loaded which will load your angular app and your config function will be invoked and it will look for the request and will give you the view

Note:- you need to put <div ng-view></div> for routing

Sign up to request clarification or add additional context in comments.

2 Comments

"When using angular routing you don't need to call a static page as you are doing home.html. you simply run your app and say you want to go home and angular routing will take you to home.html" - how would I change my JS?
Your js seems to look fine to me. How are you running your app?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.