2

我正在使用带有 AngularJS 1.5 和 ng-annotate gem 的 Rails 4.0。我注意到,当我使用“ng-strict-di”强制您在 AngularJS 中注释所有直接注入时,我发现 Rails 抱怨具有“ngInject”的模块。

例如; 这是我的 Angular 应用程序控制器

ApplicationController = (
  $scope, $timeout,
  hotkeys
  ShortcutService) ->
  "ngInject"
<SNIP>

我在模板中启用了 ng-strict-di

<html ng-app='paisApp' ng-strict-di>

当我在开发模式下运行我的应用程序时,控制台中出现错误;

Error: [$injector:strictdi] ApplicationController is not using explicit annotation and cannot be invoked in strict mode
http://errors.angularjs.org/1.5.11/$injector/strictdi?p0=ApplicationController
minErr/<@http://localhost:3000/assets/angular/angular.self.js?body=1:69:12
annotate@http://localhost:3000/assets/angular/angular.self.js?body=1:4006:17
injectionArgs@http://localhost:3000/assets/angular/angular.self.js?body=1:4733:21
instantiate@http://localhost:3000/assets/angular/angular.self.js?body=1:4784:18
$controller@http://localhost:3000/assets/angular/angular.self.js?body=1:10608:18
controllerDecorator/<@http://localhost:3000/assets/app/bower_components/angular-material-data-table/dist/md-data-table.self.js?body=1:321:12
compile/<@http://localhost:3000/assets/angular-ui-router/angular-ui-router.self.js?body=1:9781:46
bind/<@http://localhost:3000/assets/angular/angular.self.js?body=1:1260:15
invokeLinkFn@http://localhost:3000/assets/angular/angular.self.js?body=1:10153:9
nodeLinkFn@http://localhost:3000/assets/angular/angular.self.js?body=1:9552:11
compositeLinkFn@http://localhost:3000/assets/angular/angular.self.js?body=1:8811:13
publicLinkFn@http://localhost:3000/assets/angular/angular.self.js?body=1:8691:30
lazyCompilation@http://localhost:3000/assets/angular/angular.self.js?body=1:9048:16
updateView@http://localhost:3000/assets/angular-ui-router/angular-ui-router.self.js?body=1:9719:38
configUpdatedCallback@http://localhost:3000/assets/angular-ui-router/angular-ui-router.self.js?body=1:9663:25
configureUIView@http://localhost:3000/assets/angular-ui-router/angular-ui-router.self.js?body=1:5640:17
ViewService.prototype.sync@http://localhost:3000/assets/angular-ui-router/angular-ui-router.self.js?body=1:5645:9
activateViews@http://localhost:3000/assets/angular-ui-router/angular-ui-router.self.js?body=1:6273:5
invokeCallback@http://localhost:3000/assets/angular-ui-router/angular-ui-router.self.js?body=1:1580:20
TransitionHook.prototype.invokeHook@http://localhost:3000/assets/angular-ui-router/angular-ui-router.self.js?body=1:1592:26
TransitionHook.runAllHooks/<@http://localhost:3000/assets/angular-ui-router/angular-ui-router.self.js?body=1:1719:48
TransitionHook.runAllHooks@http://localhost:3000/assets/angular-ui-router/angular-ui-router.self.js?body=1:1719:9
transitionSuccess@http://localhost:3000/assets/angular-ui-router/angular-ui-router.self.js?body=1:3432:13
processQueue@http://localhost:3000/assets/angular/angular.self.js?body=1:16697:28
scheduleProcessQueue/<@http://localhost:3000/assets/angular/angular.self.js?body=1:16713:27
$eval@http://localhost:3000/assets/angular/angular.self.js?body=1:17995:16
$digest@http://localhost:3000/assets/angular/angular.self.js?body=1:17809:15
$apply@http://localhost:3000/assets/angular/angular.self.js?body=1:18103:13
done@http://localhost:3000/assets/angular/angular.self.js?body=1:12083:36
completeRequest@http://localhost:3000/assets/angular/angular.self.js?body=1:12292:7
requestLoaded@http://localhost:3000/assets/angular/angular.self.js?body=1:12220:9
 <div id="wrapper" ui-view="" class="ng-scope" data-ng-animate="1">
angular.self.js:14200:18

如果我手动对此进行注释,那么该文件的错误就会消失。我有很多 angularJS 文件,所以我不想为每个文件都这样做。

更新

我正在使用 NG_FORCE=true 运行我的服务器,就像这样;

NG_FORCE=true RAILS_ENV=development bundle exec rails s
4

0 回答 0