0

I'm trying to implement an answer on another StackOverflow question, using a link in the header to redirect Index.html's ng-view.

When loading pages directly via: http://server/#/page the app works without issue (no console errors, page renders correctly, angular/js logic runs correctly). My routing logic returns 'undefined' when I step through the logic (into the angular library), delivering me to http://server/# which is a great page of nothingness, except the header and footer render correctly.

I'm not sure what I'm doing incorrectly.

I'm going to be selective as to what I include code wise (just to keep this at a reasonable length) but if I left something important out, don't hesitate to request it.

Index.html:

<!DOCTYPE html>
<html ng-app="passwordResetApp">
<head>
    <title>COP Azure B2B Password Reset</title>
    <meta charset="utf-8"/>
    <!--Lib-->
        <!--ng base-->
            <script src="app/lib.bower/angular/angular.js"></script>
            <script src="app/lib.bower/angular-route/angular-route.js"></script>   
        <!--ui grid-->
            <script src="app/lib.bower/angular-ui-grid/ui-grid.min.js"></script>
            <link href="app/lib.bower/angular-ui-grid/ui-grid.min.css" rel="stylesheet"/>
        <!--Misc-->
            <link rel="stylesheet" href="app/lib.bower/bootstrap/dist/css/bootstrap.min.css" />
    <!--Custom-->
    <script src="app/app.js"></script>
    <!--Custom - Services-->
    <script src="app/services/resetRequestService.js"></script>
    <script src="app/services/adValidationService.js"></script>
    <!--Custom - Controllers-->

    <script src="app/controllers/HeaderController.js"></script>
    <script src="app/controllers/PasswordResetRequestController.js"></script>
    <!--Custom modules-->
    <script src="app/modules/header.js"></script>
    <!--Custom - Other-->
    <link rel="stylesheet" href="app/css/passwordReset.css"/>

</head>
<body ng-app>
<div class="container">
    <!--<div ng-include="'app/views/_header.html'"></div>-->
    <div header></div>
    <div class="viewWrapper">
        <div ng-view></div>
    </div>
    <div class="push"></div>
</div>
<div ng-include="'app/views/_footer.html'"></div>
</body>
</html>

app.js:

(function() {
    'use strict';

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

    app
        .config(
        function($routeProvider) {
            $routeProvider.when('/', {
                templateUrl: 'app/views/passwordReset.html',
                controller: 'ResetRequestController as vm',
                caseInsensitiveMatch: true
            }).when('userSearch', {
                templateUrl: 'app/views/userSearch.html',
                controller: 'ResetRequestController as vm',
                caseInsensitiveMatch: true
            }).otherwise({ redirectTo: '/' });
        }
    );

    app.directive('header',
        function() {
            return {
                restrict: 'A',
                //This menas that it will be used as an attribute and NOT as an element. I don't like creating custom HTML elements
                replace: true,
                templateUrl: 'app/views/_header.html',
                controller: 'HeaderController as vm',
                caseInsensitiveMatch: true
            }
        });

    app.run([
        '$route', '$http', '$rootScope',
        function ($route, $http, $rootScope) {
            $http.defaults.withCredentials = true;
            $rootScope.getUrlPath = function (url) {
                return baseUrl + url;
            };
        }
    ]);
}());

_header.html:

<header id="pageHeader">
    <div class="row">
        <div class="col-sm-4 col-md-3 col-lg-2 cop-logo-container">
            <img id="cop-logo" src="app/img/ConocoPhillips_Logo.png" />
        </div>
        <div class="col-sm-4 col-md-6 col-lg-8">
            <h2>Azure B2B Password Reset</h2>
            {{vm.currentUser.name}}
        </div>
        <div class="col-sm-4 col-md-3 col-lg-2">
            <div class="pull-right" style="padding: 20px">
                <div ng-if="vm.currentUser" id="headerUser">
                    <p>Welcome, <span class="username">{{vm.currentUser.name}}</span></p>
                </div>
                <div ng-if="!vm.currentUser">
                    <div class="btn btn-primary">Login</div>
                </div>
            </div>
        </div>
    </div>
    <nav class="navbar navbar-default">
        <div class="container-fluid">
            <div class="navbar-header">
                <ul ng-if="vm.currentUser" class="nav navbar-nav">
                    <li><a href="#" ng-click="vm.changeView('home')">Home</a></li>
                    <li><a href="#" ng-click="vm.changeView('userSearch')">Search Users</a></li>
                    <li><a href="#" ng-click="vm.logout()">Logout</a></li>
                </ul>
                <ul ng-if="!vm.currentUser" class="nav navbar-nav">
                    <li><a href="#" ng-click="vm.changeView('home')">Home</a></li>
                </ul>
            </div>
        </div>
    </nav>
</header>

HeaderController.js:

(function() {
    'use strict';

    var app = angular.module('passwordResetApp');

    var headerController = function ($scope, $location) {
        var vm = this;
        vm.currentUser = {};
        vm.currentUser.name = 'caninc';

        vm.changeView = function(view) {
            $location.path(view);
        }
    };

    app.controller('HeaderController', headerController);


}());
Community
  • 1
  • 1
Ranger
  • 1,139
  • 1
  • 13
  • 34
  • Do you have CORS activated, check robots.txt ? Is this type of same origin or cross origin? – grzesiekmq May 18 '16 at 22:53
  • @Grisza This is on localhost; website is currently in development. I don't have a robots.txt, and I... honestly don't know what CORS is to check. – Ranger May 18 '16 at 22:54
  • @Grisza In the context of it being hosted on localhost, what do you mean? Do you mean other files on localhost? The LAN? The Internet? The computer (localhost) itself has all of these things, although I don't understand how that would have to do with internal angularjs routing. – Ranger May 18 '16 at 22:57

1 Answers1

2

Issue is with <li><a href="#" ng-click="vm.changeView('home')">Home</a></li>

# so when clicked http://server/# not http://server/#/page

grzesiekmq
  • 419
  • 1
  • 6
  • 17