AngularJS 找不到具有最新 RequireJS 的模块 [英] AngularJS cannot find module with latest RequireJS

查看:24
本文介绍了AngularJS 找不到具有最新 RequireJS 的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚升级到 RequireJS 2.1.1 - 我正在加载一个 AngularJS 应用程序.在主定义运行之前,我从 angular 得到No module: app".

I just upgraded to RequireJS 2.1.1 - I have an AngularJS app I'm loading with it. I get "No module: app" from angular before the main define runs.

它在 RequireJS 2.0.1 上运行良好.知道可能发生了什么变化吗?

It works fine on RequireJS 2.0.1. Any idea what might have changed?

这里是 public/index.html

Here's is public/index.html

<!doctype html>
<html lang="en" ng-app="app">
<head>
  <meta charset="utf-8">
  <title>AngularJS</title>
  <link rel="stylesheet" href="css/style.css"/>
  <script data-main="main" src="requirejs/require.js"></script>
</head>
<body>
  <div ng-view></div>
</body>
</html>

这里是 public/main.coffee

And here is public/main.coffee

require.config

  shim:
    underscore: exports: '_'
    ngResource:
      exports: 'angular'
      deps: ['angular']
    angular:
      exports: 'angular'
      deps: ['jquery']
    jquery: exports: 'jQuery'

  paths:
    underscore: 'underscore/index'
    angular: 'AngularJS/angular'
    ngResource: 'angular-modules/resource'
    jquery: 'jquery/jquery'

# Bootstrap angularjs using requirejs. 
define [], (require) ->
  angular = require 'angular'
  ngResource = require 'ngResource'

  TestCtrl = require 'controllers/TestCtrl'

  ## ROUTER ###########
  app = angular.module 'app', ['ngResource'], ($routeProvider) ->
    $routeProvider.when '/test', {templateUrl: 'partials/test.html', controller: TestCtrl}
    $routeProvider.otherwise {redirectTo: '/test'}

  return app

推荐答案

在这种情况下,您应该手动引导 angular 并删除 ng-app 属性,因为该模块在 dom 就绪时不可用:

You should manually bootstrap angular and remove the ng-app attribute in that case since the module is not available on dom ready:

angular.bootstrap document, ['app']

在定义函数的末尾

这篇关于AngularJS 找不到具有最新 RequireJS 的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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