2

It seems that by asking this question, I am just beating a dead horse, but I have been through all the posts that I could find and still could not find an answer. I (and even a colleague) have spent countless hours trying to solve what seems to be a relatively basic concept. So , can I please get some help with my angularjs routing

index.html:

<!DOCTYPE html>
<html lang="en" ng-app="foodApp">

<head>
    <meta charset="utf-8" />
    <title>What Do I Eat</title>

    <link href="/app/css/app.css" rel="stylesheet" />
    <link href="/Content/bootstrap.min.css" rel="stylesheet" />

    <script src="/Scripts/jquery-1.9.1.min.js"></script>
    <script src="/Scripts/bootstrap.min.js"></script>
    <script src="/Scripts/angular.js"></script>
    <script src="/Scripts/angular-resource.min.js"></script>
    <script src="/Scripts/angular-route.min.js"></script>
    <script src="/app/js/app.js"></script>

    <script src="/app/js/controllers/ExistingRestaurantController.js"></script>
    <script src="/app/js/controllers/NewExperienceController.js"></script>
    <script src="/app/js/controllers/NewRestaurantController.js"></script>
    <script src="/app/js/controllers/indexController.js"></script>
    <script src="/app/js/services/RestaurantData.Service.js"></script>
</head>

<body>
    <header class="container-fluid">
        <h1>What Do I Eat</h1>
    </header>
    <div class="container-fluid">
        <div class="navbar">
            <div class="navbar-inner">
                <ul class="nav">
                    <li><a href="#/myRest">My Restaurants</a></li>
                    <li><a href="#/addRest">Add Restaurant</a></li>
                    <li><a href="#/addExp">Add Experience</a></li>
                </ul>
            </div>
        </div>

        <ng-view></ng-view>

    </div>
    <footer class="container-fluid">
        whatever i want
    </footer>
</body>
</html>

app.js:

'use strict';

var foodApp = angular.module('foodApp', ['ngResource', 'ngRoute']);

foodApp.config(['$routeProvider',
    function ($routeProvider) {
        $routeProvider
            .when('/myRest',
            {
                templateUrl: '/templates/ExistingRestaurant.html',
                controller: 'ExistingRestaurantController'
            })
            .when('/addExp',
            {
                templateUrl: '/templates/NewExperience.html',
                controller: 'NewExperienceController'
            })
            .when('/addRest',
            {
                templateUrl: '/templates/NewRestaurant.html',
                controller: 'NewRestaurantController'
            });
    }
]);

ExistingRetaurantController.js

'use strict';

foodApp.controller('ExistingRestaurantController',
    function ExistingRestaurantController($scope) {

        $scope.restaurant = {
            name: 'Cheesecake Factory',
            food: 'Cheesecake',
            price: 6.95
        }
    }
);

ExistingRestaurant.html:

<div class="container-fluid">
    <h1>Existing Page!</h1>
</div>
Stryderr
  • 41
  • 6
  • Any error in console? – Developer Jan 31 '17 at 16:38
  • Should have nothing to do with Visual Studio. Are you working with the .NET MVC framework? If so, it uses the routing from the `RouteConfig.cs` file. From my experience, angular routing and the .NET MVC routing do not play nicely together - although I would imagine any two routing engines pitted against each other would have similar problems – mhodges Jan 31 '17 at 16:40
  • No errors in console – Stryderr Jan 31 '17 at 16:43
  • @mhodges no, I started with a blank site. I added the VS 2015 for a reference to the WebServer as that was a topic on many of the other closely related questions. – Stryderr Jan 31 '17 at 16:49
  • Try specifying `index.html` explictly in the url - if you haven't already, just thinking VS won't put it in by default if there are no default routes set up. – Matthew Cawley Jan 31 '17 at 16:52
  • Also add a default route to your angular routing using `.otherwise({ redirectTo: "/myRest" });` or similar. – Matthew Cawley Jan 31 '17 at 16:57
  • And... make note that the routes are case sensitive unless you add the `caseInsensitiveMatch: true` property to your routes - my guess is it's this one, the cause of many a headache!. – Matthew Cawley Jan 31 '17 at 16:58
  • @MatthewCawley this is my starting Url : http://localhost:2421/app/index.html and strangely when i click a one of my links, this is the new Url: http://localhost:2421/app/index.html#!#%2FmyRest but absolutely nothing happens – Stryderr Jan 31 '17 at 17:13
  • @MatthewCawley that is exactly how my URL looks. Is what is in the index.html (
  • My Restaurants
  • Add Restaurant
  • Add Experience
  • ) not what you are looking for? – Stryderr Jan 31 '17 at 17:29
  • Okay thanks, and try one of those links without the hash. `
  • My Restaurants
  • ` – Matthew Cawley Jan 31 '17 at 17:34
  • @MatthewCawley been way up and down that road, but tried again, and still a no go – Stryderr Jan 31 '17 at 17:59
  • Okay, it's a tough one, my last attempt, add `` to your head tag!? – Matthew Cawley Jan 31 '17 at 18:09
  • Index.html would normally be outside of the app folder by the way, whereas yours appears to be nested within it!? – Matthew Cawley Jan 31 '17 at 18:16