Angularjs引发TypeError:无法读取的未定义的属性'的indexOf“ [英] Angularjs throws TypeError: Cannot read property 'indexOf' of undefined

查看:1345
本文介绍了Angularjs引发TypeError:无法读取的未定义的属性'的indexOf“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图调试上述code,我觉得这是非常有用的><

I'm trying to debug the above code which I feel like this is very useful >.<

我甚至不能找到什么是错在我的code和真的不知道在哪里,因为Angularjs还是开始很新的给我。

I can't even find what is wrong in my code and don't really know where to start since Angularjs still very new to me.

我试图本地化Angularjs应用程序。我知道这是缺少了许多方面,以获得帮助,但我想看到我应该给什么样的信息,这将有助于在这个调试。

I'm trying to localize Angularjs app. I know this is missing a lot of context in order to get a help, but I'm trying to see what information that I should give that would help on this debugging.

我已经通过任何的indexOf angularjs 文件消失了,我可以看到几件事情是未定义,但不知道这是否将是有益的。

I've gone through any indexOf in angularjs file and I can see few things is undefined but don't know if that would be helpful.

所以,我在这里跟踪的问题,这是我想通的问题,但仍counldn't弄清楚为什么...

So I've traced the problem here and this is what I have figured is the problem, but still counldn't figure out why...

config(['$routeProvider', '$locationProvider',
  function ($routeProvider, $locationProvider) {
    $routeProvider.when('/:locale?/:username/badges', {
      templateUrl: '_partials/badges.html',
      controller: 'badges'
    })
    .when('/:username/badges', {
      templateUrl: '_partials/badges.html',
      controller: 'badges'
    })
    .when('/:username/teaching-resources', {
      templateUrl: '_partials/teaching-resources.html',
      controller: 'teachingResources'
    })
    .when('/:username/makes', {
      templateUrl: '_partials/makes.html',
      controller: 'makes'
    })
    .when('/:username/likes', {
      templateUrl: '_partials/likes.html',
      controller: 'likes'
    })
    .when('/:username/events', {
      templateUrl: '_partials/events.html',
      controller: 'events'
    })
    .when('/:username', {
      templateUrl: '_partials/badges.html',
      controller: 'badges'
    });

    $routeProvider.otherwise({
      redirectTo: '/error/404'
    });

这是我访问默认网页的URL为:

The URL that I'm visiting for default page is:

这将失败,并抛出错误。

This will fail and throw the error.

http://localhost:1969/en-US/user/someUserName

这将正常工作

http://localhost:1969/user/someUserName

更新

我想通了!这就是问题:

UPDATE

I figured out! This is the problem:

  $locationProvider.html5Mode(true);

但是,为什么!?

But why!?

推荐答案

我有同样的错误。为了使用html5Mode您需要确保将&LT;基本href =/&GT; 标签在你的头正确的URL。查看 $位置服务文档了解详情。

I had the same error. In order to use html5Mode you need to make sure to set the <base href="" /> tag to the correct URL in your header. Check out the $location service docs for details.

这篇关于Angularjs引发TypeError:无法读取的未定义的属性'的indexOf“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆