AngularJS无法找到最新的RequireJS模块 [英] AngularJS cannot find module with latest RequireJS

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

问题描述

我刚刚升级到2.1.1 RequireJS - 我有一个AngularJS应用我加载它。我得到无模块:应用程序,从角前的主要运行定义。

它适用于RequireJS 2.0.1罚款。任何想法发生了什么改变?

下面的是公共/ index.html的

 <!DOCTYPE HTML>
< HTML LANG =ENNG-应用=应用程序>
< HEAD>
  <间的charset =UTF-8>
  <标题> AngularJS< /标题>
  <链接rel =stylesheet属性HREF =CSS / style.css文件/>
  <脚本数据主要=主SRC =requirejs / require.js>< / SCRIPT>
< /头>
<身体GT;
  < D​​IV NG-视图>< / DIV>
< /身体GT;
< / HTML>

这是公共/ main.coffee

  require.config  垫片:
    强调:出口:'_'
    ngResource:
      出口:'角'
      DEPS:['角']
    角度:
      出口:'角'
      DEPS:['jQuery的']
    jQuery的:出口:jQuery的  路径:
    强调:下划线/索引
    角:AngularJS /角
    ngResource:角模块/资源
    jQuery的:jQuery的/ jQuery的'#引导angularjs使用requirejs。
定义[],(需要) - GT;
  角=需要'角'
  ngResource =需要'ngResource  TestCtrl =需要控制器/ TestCtrl  ## ROUTER ###########
  应用= angular.module'应用',['ngResource'],($ routeProvider) - GT;
    $ routeProvider.when'/测试',{templateUrl:'谐音/ test.html的',控制器:TestCtrl}
    $ {routeProvider.otherwise redirectTo:'/测试'}  返回应用


解决方案

您应该手动引导的角度,并删除在这种情况下,NG-应用属性,因为该模块无法使用DOM的准备:

  angular.bootstrap文件,['应用']

在你定义函数结束

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.

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

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>

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

解决方案

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']

at the end of your define function

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

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