这是main.js:
require.config({ baseUrl: "http://localhost/ums/angular/js",paths: { 'angular': 'lib/angular.min','ngRoute': 'lib/angular-route.min','flash': 'lib/angular-flash','angular-loading-bar': 'lib/loading-bar.min','ngAnimate': 'lib/angular-animate.min','ui.bootstrap': 'lib/ui-bootstrap-tpls-0.12.0','uniqueField': 'admin/directives/angular-unique','input_match': 'admin/directives/angular-input-match','uniqueEdit': 'admin/directives/angular-unique-edit','angularAMD': 'lib/angularAMD.min','chart.js': 'lib/Chart.min','angular-chart':'lib/angular-chart.min','app': 'admin/app',},waitSeconds: 0,shim: { 'angular': { exports: 'angular'},'angularAMD': { deps: ['angular']},'angular-chart': { deps: ['angular','chart.js']},'ngRoute':{ deps: ['angular']},'angular-loading-bar':{ deps:['angular'] },'ngAnimate': { deps:['angular'] },'ui.bootstrap': {deps: ['angular'] },'uniqueField': {deps: ['angular'] },'input_match': {deps: ['angular'] },'uniqueEdit': {deps: ['angular'] },'flash': {deps: ['angular'] },deps: ['app'] });
这是app.js:
var base_url="http://localhost/ums/"; define(['angularAMD','ngRoute','flash','angular-loading-bar','ngAnimate','uniqueField','input_match','angular-chart'],function (angularAMD) { var app = angular.module('angularapp',['ngRoute','angular-chart']); app.config(['$routeProvider',function($routeProvider){ $routeProvider .when('/dashboard',angularAMD.route({ title : 'Dashboard',controller : 'dashboardCtrl',templateUrl : base_url+'angular/partials/admin/dashboard.PHP',controllerUrl: base_url+'angular/js/admin/controllers/dashboardCtrl.js' })) //.......................all routing ............// .otherwise({ redirectTo : '/dashboard' }); }]); app.run(['$rootScope','$route',function($rootScope,$route) { $rootScope.$on('$routeChangeSuccess',function() { document.title = $route.current.title; }); }]); // Bootstrap Angular when DOM is ready return angularAMD.bootstrap(app); });
如何实现它们之间的依赖?
有什么建议么?任何例子?
If a module ID has one of the following characteristics,the ID will
not be passed through the “baseUrl + paths” configuration,and just be
treated like a regular URL that is relative to the document:
• Ends in “.js”.
• Starts with a “/”.
• Contains an URL protocol,like “http:” or “https:”.
这将启动您的chart.js模块,RequireJS将尝试从包含运行RequireJS的HTML页面的目录中加载chart.js
注意 – 您应该可以在开发者工具>中看到这一点.网络选项卡.请注意,对chart.js的请求不会转到您期望的路径.
这似乎是一个错误(带有角度图表) – 请参阅类型问题:typeahead.js – https://github.com/twitter/typeahead.js/issues/1211
>修改角度图表代码,使预期的模块ID成为没有点的东西 – 比如chartjs.然后将上面配置中的chart.js更改为chartjs.这将是正确的方式.
>将chart.min.js文件重命名为chart.js,并将其放在与运行RequireJS的html文件相同的文件夹中.这最多只是一个非常临时的修复.
>将nodeIDCompat设置为true – 这将使模块ID something.js等效于某事.然后将配置中的模块ID更改为图表.所以像
require.config({ nodeIdCompat: true,paths: { 'chart': base_url + '/lib/Chart.min',...