简体   繁体   English

$ locationProvider.html5Mode不是函数

[英]$locationProvider.html5Mode is not a function

Hey I am trying to enable html5 in my angular project based on this blog but using ui-router https://scotch.io/tutorials/pretty-urls-in-angularjs-removing-the-hashtag and the angular docs 嘿,我正在尝试根据此博客在我的角度项目中启用html5,但使用ui-router https://scotch.io/tutorials/pretty-urls-in-angularjs-removing-the-hashtag和角度文档

https://docs.angularjs.org/api/ng/provider/ $locationProvider https://docs.angularjs.org/api/ng/provider/ $ locationProvider

Basically I keep getting an error saying that html5Mode is not a function and it's confusing me as to why. 基本上,我总是收到一个错误消息,说html5Mode不是一个函数,这使我感到困惑。

I have included it in my config file and adapted the urls including a base url. 我已经将其包含在配置文件中,并修改了包括基本URL在内的URL。 It all works fine but as soon as I add 一切正常,但我一添加

$locationProvider.html5Mode()

I get an error saying it's not a function. 我收到一个错误消息,说它不是一个函数。 So I guess my question is has the function name changed, am I missing a dependency, and if not why is this not working? 所以我想我的问题是函数名称已更改,我是否缺少依赖项,如果不是,为什么这不起作用? In advance thank you for taking the time to help me. 预先感谢您抽出宝贵的时间来帮助我。

   angular.module('myApp', [
   'ui.router',
   'ui.bootstrap',
    'ngTouch',
    'ngAnimate',
   'myApp.version'

   ]). 
config(['$stateProvider', '$urlRouterProvider', '$locationProvider', function($stateProvider, $locationProvider) {


    $locationProvider.html5Mode({

        enabled: true

    });

  $stateProvider
      .state('home' , {

        url: '/home',
        templateUrl: 'app/landingPage/landingPage.html'

      })

      .state('landingPage', {

        url: '/landing-page',
        templateUrl: 'app/homePage/homePage.html'


  })



 }]);

您忘记注入$ urlRouterProvider作为第二个参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM