AngularJS + Rails的:后退按钮"警告:试图装入不止一次角度更" [英] AngularJS + Rails: Back Button "WARNING: Tried to load angular more than once."

查看:177
本文介绍了AngularJS + Rails的:后退按钮"警告:试图装入不止一次角度更"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以去我的应用程序和更改页面没有问题。使用后退按钮也是没有问题的......除非我回到在我第一次打开应用程序中的历史点。因此,指数 - >第1 - >首页 - > PG 2让我preSS后退按钮两次,回到我的索引,然后PG 1.下一回的点击率这个错误和NG-视图不负载:

I can go my app and change pages without an issue. Using the back button is also not a problem...unless I return to the point in the history where I first opened the application. So, index -> pg 1 -> index -> pg 2 allows me to press the back button twice, returning me to the index and then pg 1. The next back click yields this error and the ng-view does not load:

"WARNING: Tried to load angular more than once."

很明显,通常后退按钮只是使用$ routeProvider它看起来像这对我来说(多条航线比显示,但结构是一样的)

It's clear that usually the back button is just using the $routeProvider which looks like this for me (more routes than shown, but the structure is the same)

  .config(['$routeProvider',
    function($routeProvider) {
      $routeProvider.
        when('sampleUrl', {
          templateUrl: 'sampleTemplate',
          controller: 'sampleCtrl'
        }).
        otherwise({
          redirectTo: 'sampleUrl'
        });
    }]);

不过,最后返回按钮不再仅仅只用$ routeProvider更新NG-观点,也重装Rails的布局保存的NG-视图。布局的一般结构如下

However the last back button no longer is merely using just the $routeProvider to update the ng-view but also reloading the Rails layout that holds the ng-view. The general structure of the layout is as follows

%html{ 'ng-app' => 'myApp' }
  %body#dashboard(ng-controller='baseCtrl')
     navbar stuff
     %section.clearfix.aaux(ng-view)
javascript include tag for rails asset pipeline

我的Rails根看起来像这样

My Rails root looks like this

  root "dashboard/patients#index"

下面是我已经看了/到目前为止设想:

Here's what I've looked at/contemplated so far:

试图加载角超过一次

无关。我templateUrl是所有路线正确;除非我点击回到开始一切都很好,很正常。

Irrelevant. My templateUrl is correct for all routes; unless I click back to the beginning all is fine and dandy.

但是如果你的templateUrl是错误的,那么就会造成一个递归的
  重载的index.html加载角(和其他一切)及以上
  在

"But if your templateUrl is wrong, then it will cause a recursion that reloads index.html loading angular (and everything else) over and over."

可能是相关的,因为它是重新加载页面,上面有NG-的应用程序,我相信也是index.html的是,在其应用的东西。但是从我所看到的Rails应用程序的角度与整合是普遍的做法是在

might be relevant, as it is reloading the page with ng-app on it which I believe is also what index.html is in their app. But from what I've seen of Rails apps integrating with Angular it's common practice to put the

%html{ 'ng-app' => 'ekoApp' }

上的布局。

<一个href=\"http://stackoverflow.com/questions/23499853/warning-tried-to-load-angular-more-than-once-angular-js\">WARNING:试图加载不止一次角多。角JS

我肯定只有我一个申请NG-应用程序,但它是正装的两倍。无论如何,没有额外的NG-应用删除,这种解决方案不是特别有帮助。

I definitely only have one ng-app in my application, but it IS being loaded twice. Regardless, without an extra ng-app to delete, this solution wasn't particularly helpful.

我最近的想法是,有可能是一个时髦具有根到一个空的html页面,并使用我的布局呈现NG-视图,而不是一个Rails视图。

My most recent thought is that there might be something funky with having a root to an empty html page and using my layout to render the ng-view rather than a Rails view.

任何想法?

编辑:

拿走了一切东西在体内转化中的index.html,然后在布局只是做

Took everything in the body into the index.html and then within the layout just did

= yield

局势依然完全相同。

The situation remains exactly the same.

推荐答案

删除turbolinks解决了这个问题。我曾以为这是罚款,因为这是唯一奇怪的错误我得到的,但想不会。我很困惑,为什么有人却导致此问题,因此任何解释,即涵盖了彻底的,我会标记为正确答案。

Removing turbolinks solved the problem. I had assumed it was fine since this was the only weird error I was getting, but guess not. I'm confused as to why it was causing this problem however, so any explanation that covers that thoroughly I'll mark as the right answer.

另外,我不知道是否有人需要首先使我的布局呈现Rails视图(index.html的),然后在轨道中查看具有NG-观点,但我也没有,取消turbolinks之前(正如我上面我的编辑说的)

Also, I don't know if it was required to first make my layout render a Rails view (index.html) and then within the rails view having the ng-view, but I also did that before removing the turbolinks (as I said in my edit above)

这篇关于AngularJS + Rails的:后退按钮&QUOT;警告:试图装入不止一次角度更&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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