为什么system.js返回一个空对象而不是angularjs?

时间:2015-08-27 18:39:48

标签: javascript ecmascript-6 systemjs

为什么system.js返回一个空对象而不是angularjs?如何解决?

System.config({
  map: {
    angular: 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.3/angular.js'
  }
});

System.import('angular').then(function(data){
  console.log('###', data);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.18.4/system.js"></script>

2 个答案:

答案 0 :(得分:1)

因为AngularJS是在全局级别加载的,not as a module.

执行导入后,angular在全局范围内可用。

System.config({
  map: {
    angular: 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.3/angular.js'
  }
});

System.import('angular').then(function(){
  console.log(angular);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.18.4/system.js"></script>

答案 1 :(得分:1)

&#13;
&#13;
System.config({
  map: {
    angular: 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.3/angular.js'
  },
  meta: {
    'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.3/angular.js': {
      'format': 'global'
    }
  }
});

System.import('angular').then(function(data){
  console.log('###', data);
});
&#13;
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.18.4/system.js"></script>
&#13;
&#13;
&#13;