错误:[$ injector:nomod]模块' chart.js'不可用! Rails application.js

时间:2017-04-14 07:36:48

标签: javascript ruby-on-rails angularjs angular-chartist.js

我想让angular-chart.js在rails项目中工作。 按照https://github.com/jtblin/angular-chart.js

上的安装说明操作

1)npm install --save angular-chart.js 到现在为止还挺好。 /vendor/assets/javascripts/node_modules/angular-chart.js/(the files)

2)&#34;将源添加到您的代码中#34; 好吧,我可以在一个简单的index.html和app.js页面中使用几个<script>标签做到这一点非常成功,但我正在使用rails项目,所以我想在应用程序中加载源代码。 js显示。

3)angular.module(&#34; app&#34;,[&#34; chart.js&#34;])

我的dashboard.js.coffee已

appName = 'dashboardApp';
angular.module(appName,['ngResource', 'ui.router', 'ui.bootstrap','chart.js']);

我的application.js是

//= require jquery2
//= require jquery_ujs
//= require jquery.turbolinks
//= require select2
//= require turbolinks
//= require d3
//= require bootstrap-sass-official
//= require moment
//= require requirejs
//= require angular
//= require angular-bootstrap
//= require angular-resource
//= require angular-ui-router
//= require angular-animate
//= require angular-aria
//= require angular-material
//= require angular-websocket
//= require underscore
//= require gmaps/google
//= require slider-pro/jquery.sliderPro.js
//= require websocket_rails/main
//= require app/dashboard/Chart.bundle.js
//= require app/dashboard/angular-chart.js
//= require_tree .

减少变量我已将Chart.bundle.js和angular-chart.js复制到app javascript文件夹

.../app/assets/javascripts/app/dashboard
|-- angular-chart.js
|-- app.js
|-- Chart.bundle.js
|-- Chart.bundle.min.js
|-- _chart.html.erb
|-- dashboard.html.erb
|-- dashboard.js.coffee.erb
|-- data.html.erb.bk
|-- details.html.erb
|-- _search.html.erb
`-- test.html.erb

但我想从... / vendor / assets /文件夹中使用它们。 (我在使用该路径时遇到了同样的问题)

我认为我遇到了某种加载顺序错误。我无法弄清楚出了什么问题。 Angualrjs正在返回此错误

 Uncaught Error: [$injector:modulerr] Failed to instantiate module dashboardApp due to:
Error: [$injector:modulerr] Failed to instantiate module chart.js due to:
Error: [$injector:nomod] Module 'chart.js' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.6.1/$injector/nomod?p0=chart.js
    at http://localhost:3000/assets/angular/angular.self-bfd6c8dff7a273aef9f5716cbbd0f6cb8837cf59dd5c54eb4d9adc360007e639.js?body=1:69:12
    at http://localhost:3000/assets/angular/angular.self-bfd6c8dff7a273aef9f5716cbbd0f6cb8837cf59dd5c54eb4d9adc360007e639.js?body=1:2184:17
    at ensure (http://localhost:3000/assets/angular/angular.self-bfd6c8dff7a273aef9f5716cbbd0f6cb8837cf59dd5c54eb4d9adc360007e639.js?body=1:2108:38)
    at module (http://localhost:3000/assets/angular/angular.self-bfd6c8dff7a273aef9f5716cbbd0f6cb8837cf59dd5c54eb4d9adc360007e639.js?body=1:2182:14)
    at http://localhost:3000/assets/angular/angular.self-bfd6c8dff7a273aef9f5716cbbd0f6cb8837cf59dd5c54eb4d9adc360007e639.js?body=1:4737:22
    at forEach (http://localhost:3000/assets/angular/angular.self-bfd6c8dff7a273aef9f5716cbbd0f6cb8837cf59dd5c54eb4d9adc360007e639.js?body=1:358:20)
    at loadModules (http://localhost:3000/assets/angular/angular.self-bfd6c8dff7a273aef9f5716cbbd0f6cb8837cf59dd5c54eb4d9adc360007e639.js?body=1:4721:5)
    at http://localhost:3000/assets/angular/angular.self-bfd6c8dff7a273aef9f5716cbbd0f6cb8837cf59dd5c54eb4d9adc360007e639.js?body=1:4738:40
    at forEach (http://localhost:3000/assets/angular/angular.self-bfd6c8dff7a273aef9f5716cbbd0f6cb8837cf59dd5c54eb4d9adc360007e639.js?body=1:358:20)
    at loadModules (http://localhost:3000/assets/angular/angular.self-bfd6c8dff7a273aef9f5716cbbd0f6cb8837cf59dd5c54eb4d9adc360007e639.js?body=1:4721:5)

我是rails和angularjs的新手,所以我确信我遗漏了一些基本的东西。 任何帮助,将不胜感激。 我已经阅读了有关此主题的其他问题,但他们并没有真正给出明确答案

编辑: could this long load time be related?编辑:(不)

EDIT2: 我已尝试将以下内容放在/app/views/layout/application.html.erb文件

<%= javascript_include_tag 'https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.js' %>
<%= javascript_include_tag 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.min.js' %>
<%= javascript_include_tag 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.bundle.js' %>
<%= javascript_include_tag 'https://cdn.jsdelivr.net/angular.chartjs/latest/angular-chart.js' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>

这样做我不再得到喷油器错误。

因此,似乎是关于我如何在rails资产管道中使用angular-chart.js和chart.js。

0 个答案:

没有答案