1

I have the following code for routing to a survey. When I access it from another partial in my angular application like this '../fill/' +$scope.fill[i].id; which results in this url 'http://localhost:9000/fill/27' and everything works fine. But when I refresh the page or hit it directly with the url, it does not load anything and gives all errors these errors of not finding the source files although I added all the required sources in the same html.

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

app.config(['$routeProvider', '$locationProvider',
function($routeProvider, $locationProvider) {

    $locationProvider.html5Mode({
      enabled: true,
      requireBase: false
    });
    $routeProvider
      .when('/fill/:id', {
        templateUrl: 'fill.html',
        controller: 'fillCtrl'
      })
      .otherwise({
        redirectTo: '/'
      })
  }
]);

app.controller('fillCtrl', ['$scope', '$location', '$http', '$routeParams', function($scope, $location, $http, $routeParams) {
  $scope.id = $routeParams.id;
  console.log($scope.id);
}]);

2
  • since you are not using hashbang technology, on refresh your application is not able to load angular lib files (Assuming imported in index.html). that's why it is getting angular is not defined. Commented Aug 30, 2017 at 18:13
  • 1
    Try adding <base href="/"> in your <head> tag Commented Aug 30, 2017 at 18:21

0

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.