0

I got into a problem in routing that I can't remove # in the url. I have tried all the solutions like using $locationProvider by setting $locationProvider.html5Mode(true).href="/" is not working for me as its taking the directory wrong and all files are missing, so I have used href="./"

But an error keeps coming like Cannot read property 'html5Mode' of undefined kindly provide me a solution. Here's my snippet

var angularMFRP = angular.module('angularMFRP',['ngRoute','angularUtils.directives.dirPagination']);

angularMFRP.config(['$routeProvider','$locationProvider', function($routeProvider, $rootScope,$locationProvider) {
    $routeProvider
		.when('/', {

            templateUrl: 'app/partials/home.html',
            controller: 'home'
        })
        .when('/restaurants', {
			resolve: {

                "check": function($location, $rootScope, $window) {
                    if (!$rootScope.navigates) {
                        $window.alert("please select City");
                        $location.path('/');

                    }

                }
            },
            templateUrl: 'app/partials/restaurants.html',
            controller: 'restaurant'
        })
		.otherwise({
        redirectTo: '/'
    });
	if(window.history && window.history.pushState){
            
         $locationProvider.html5Mode({
                 enabled: true,
                 requireBase: false
          });
        } 
		
		}]);
<!DOCTYPE html>
<html lang="en" ng-app="angularMFRP">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title ng-bind="title"></title>
	<base href="./">
    <link rel="stylesheet" type="text/css" href="assets/css/reset.css">
    <link rel="stylesheet" type="text/css" href="assets/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="assets/css/style.css">

    <!-- include library script files here -->

          <script src="assets/library/angular.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.0/angular-route.min.js"></script>
    <script src="assets/library/bootstrap.js"></script>
    <script src="assets/library/dirPagination.js"></script>

</head>

But an errors keeps showing like

Error: $injector:modulerr Module Error Failed to instantiate module angularMFRP due to: TypeError: Cannot read property 'html5Mode' of undefined

Also I have used this statement alone too $locationProvider.html5Mode(true) as suggested in all sites,but its not working the error keep coming.Kindly suggest me some solution

2
  • 1
    you forgot to pass $rootScope as a element of an array in config function. angularMFRP.config(['$routeProvider','$rootScope','$locationProvider', function($routeProvider, $rootScope,$locationProvider) { Commented Oct 19, 2016 at 8:01
  • stackoverflow.com/questions/14771091/… Commented Oct 19, 2016 at 8:46

2 Answers 2

1

Try this by replacing this line near, in your code :

angularMFRP.config(['$routeProvider','$rootScope','$locationProvider', function($routeProvider, $rootScope,$locationProvider) {
Sign up to request clarification or add additional context in comments.

Comments

0
var angularMFRP = angular.module('angularMFRP', ['ngRoute', 'angularUtils.directives.dirPagination']);

angularMFRP.config(['$routeProvider', '$locationProvider',
  function($routeProvider, $locationProvider) {
    $routeProvider
      .when('/', {
        templateUrl: 'app/partials/home.html',
        controller: 'home'
      })
      .when('/restaurants', {
        resolve: {
          "check": function($location, $rootScope, $window) {
            if (!$rootScope.navigates) {
              $window.alert("please select City");
              $location.path('/');

            }

          }
        },
        templateUrl: 'app/partials/restaurants.html',
        controller: 'restaurant'
      })
      .otherwise({
        redirectTo: '/'
      });
    $locationProvider.html5Mode({
      enabled: true,
      requireBase: false
    });
  }
]);

Comments

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.