简体   繁体   English

require 没有正确加载模块

[英]require is not loading modules properly

fter including require tag the application is behaving abnormal way .is there any way i can bootstrap my application apart from below code .在包含 require 标签后,应用程序的行为方式异常。除了下面的代码之外,有什么方法可以引导我的应用程序。

main.js 

require(['/module.js'], function() {
            angular.element(document).ready(function () {
                angular.bootstrap(document, ['myApp']);
            });     
});

When I written as single file js file the code is working properly.当我编写为单个文件 js 文件时,代码工作正常。

module.js

var name = 'myApp';
angular.module(name, [])
   .controller('Controller', require(['controller.js']))
   .factory('Service', require(['service.js']))
   .filter('Number', require(['filter.js']));

I have included my main.js in index.html .我已经在 index.html 中包含了我的 main.js 。 index html has 3 views i am displaying them based on ng-show from index.html. index html 有 3 个视图,我根据 index.html 中的 ng-show 显示它们。

The problem is module.js loading properly and js files too.问题是 module.js 正确加载和 js 文件。 Script is not executing properly so that my entire index.html page including 3 views displayed automatically with error messages.脚本未正确执行,因此我的整个 index.html 页面(包括 3 个视图)自动显示错误消息。

Control is not going to controller.js/service.js控制不会转到 controller.js/service.js

Error :
Error: Unknown provider: depsProvider <- deps .

Did i miss any define code?我错过了任何定义代码吗? Thanks in advance提前致谢

Angular does not support AMD by default, You need to config angular to export angular object. Angular 默认不支持 AMD,您需要配置 angular 才能导出 angular 对象。 Please check out the this post for more details.请查看此帖子以获取更多详细信息。

require.config({

    paths: {
        'angular': '../lib/angular/angular'
    },

    shim: {
        'angular': {
            exports: 'angular'
        }
    }
});

Your module.js should be defined with define method of requirejs and it should return module.你的module.js 应该用requirejs 的define 方法定义并且它应该返回module。

You can omit file extesion (.js) while using requireJs使用 requireJs 时可以省略文件扩展 (.js)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM