0

Stumped. No issue with my code (as far as I can see), and it loads list-patents.htm template when nothing is selected, but fails to load add-patents template when the corresponding anchor tag is clicked. URL displays as follows:

http://localhost/#!/#list-patents

Any reason why the content isn't loading? Is it possibly the #! in the URL?

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
     <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular-route.min.js"></script>
</head>

<main ng-app="myApp" ng-controller="appCtrl">
    <div class="container">
        <nav>
            <ul>
                <li><a href="#list-patents">List patents</li>
                <li><a href="#add-patent">Add patent</li>
            </ul>
        </nav>
        <section class="ng-view">

        </section>
    </div>
</main>

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

app.controller('appCtrl', function($scope, $http, $rootScope) {
    $scope.stages = [
        {'stage': 'green', 'cost': '$1, 500'},
        {'stage': 'yellow', 'cost': '$1, 800'},
        {'stage': 'red', 'cost': '$2, 100'},
        {'stage': 'blue', 'cost': '$2, 500'},
        {'stage': 'brown', 'cost': '$2, 900'}
    ];
    $http.get('../scripts/patent-renewal.json').then(function(response) {
        $scope.application = response.data.patents;
    });

});

app.config(function($routeProvider){
    $routeProvider
    .when('/', {
        templateUrl: '../templates/list-patents.htm',
        controller: 'appCtrl'
    })
    .when('/add-patent', {
        templateUrl:'../templates/add-patent.htm',
        controller: 'appCtrl'
    })
});

1 Answer 1

2

The !# might indeed be the problem, why it's added no idea.

What you could try is to switch to html5 mode

  $locationProvider.html5Mode(true);

And then your href can be direct, without #:

<li><a href="list-patents">List patents</li>
<li><a href="add-patent">Add patent</li>
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! It works, had to specify a base URL and as you stated remove the #. Still would like to know why there is an issue..... anyways, thanks again

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.