AngularJs2与AMD加载器(dojo requirejs)集成

现在是西太平洋时间凌晨,这个问题我鼓捣了一天,都没时间学英语了,英语太差,相信第二天我也看不懂了,直接看结果就行。
核心原理就是require在AngularJs2编译过程中是关键字,而在浏览器里面运行时候AngularJs2不会去关心require方法。所以只要在原始的ts代码中不出现require就没问题。所以在AMD的加载器加载完毕之后,立即用一个全局变量保存,在AngularJs2的代码中使用这个全局变量在做加载器。
Because require is a key word of Angular, RequireJs will conflict with Angularjs.
The reason angular use commonjs modular specification, it need to compile to js for run in browsers.
If you used require in code angularjs2 , the expression will be compiled to another style:

require(['dojo/_base/html'], (html) => {
      console.log(html);
    }); 

var html = __webpack_require__(['dojo/_base/html']);
console.log(html);

But if you the code in runing, the require will works fine.
image
This means Angularjs2 never replace the require when your app run in browsers.
So there have a perfect way to integrate requireJs within AngularJs2.

  <script>
    dojoConfig = {
      async: true,
      parseOnLoad: false
    }
  </script>
  <script src="//js.arcgis.com/3.17/"></script>
  <script type="text/javascript">
    dojoRequire = require;
  </script>

image

转载于:https://www.cnblogs.com/dojo-lzz/p/5688440.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值