嵌套的ng-include使AngularJS无限加载

时间:2016-01-19 12:58:47

标签: javascript html ruby-on-rails angularjs coffeescript

我有一个带有 assets filetree 的Rails 4应用程序:

- Assets
- - Javascripts
- - - ng-controllers
- - - - parrotsController.coffee
- - - ng-views
- - - - partials
- - - - - _parrots_index.html.slim
- - - - - _parrots_index_paginator.html.slim
- - - - home.html.slim
- - - app.coffee
- - - routes_config.coffee

routes_config.coffee

...
    $routeProvider
      .when '/',
        templateUrl: 'ng-views/home.html',
        controller: 'ParrotsController as vm' # Modern 'as' syntax
                                              # 'vm' goes for ViewModel
      .otherwise
        redirectTo: '/'
...

home.html.slim

...
  div ng-include="'ng-views/partials/_parrots_index.html'"
...

_parrots_index.html.slim

...
  tr ng-include="'ng-views/partials/_parrots_index_paginator.html.slim'"
...

_parrots_index_paginator.html.slim

td
  | Some content, no models here

所以,如果我不在 _parrots_index.html.slim 中包含 _parrots_index_paginator.html.slim ,只是插入其代码,就可以正常< / strong>(即使它被插入两次)。

但是,保留上面列出的代码中的所有内容会导致无限的资源加载。为什么呢?

我的 Gemfile

gem 'jquery-rails'
gem 'angularjs-rails', git: 'https://github.com/ScoutRFP/angularjs-rails' # <- Better fork
gem 'angular-rails-templates'
gem 'angular_rails_csrf'

application.coffee

#= require jquery
#= require jquery_ujs
#= require bootstrap-sprockets
#= require angular
#= require angular-resource
#= require angular-route
#= require angular-animate
#= require angular-rails-templates
#= require angular-bootstrap/ui-bootstrap-tpls.min
#= require angular-loading-bar

#= require_tree .

感谢您的帮助,如果您需要更多代码,请与我们联系。

1 个答案:

答案 0 :(得分:0)

_parrots_index.html.slim的示例中,您有:

...
tr ng-include="'ng-views/partials/_parrots_index_paginator.html.slim'"
...

不应该包含HTML文件(不是.slim)?