且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

有没有办法在没有任何模块加载器的情况下使用angular 2?

更新时间:2023-09-07 14:15:46

是的,您可以使用普通的ES5 javascript.尝试这个简单的示例.

Yes, you can use plain ES5 javascript. Try this simple example.

此外,您还可以尝试在官方javascript 5分钟快速入门中进行创建考虑"ES5 JavaScript没有本机模块系统.可以使用几种流行的第三方模块系统的示例.为了简单起见并避免选择偏好,我们将为应用程序创建一个全局名称空间. .

Also, you can try the oficial javascript 5 min quickstart where they create an example considering that "ES5 JavaScript doesn't have a native module system. There are several popular 3rd party module systems we could use. Instead, for simplicity and to avoid picking favorites, we'll create a single global namespace for our application.".

单个全局名称空间(并加载教程中描述的正确脚本(angular2-all.umd.js等))是无需模块加载器即可运行的方法之一.

That single global namespace (and loading the correct scripts described in the tutorial (angular2-all.umd.js, etc.)) is one of the ways to run without a module loader.

此结构也适用于Typescript或ES6.您只需要添加自己喜欢的翻译器( Babel

This structure also works with Typescript or ES6. You only need to add your favorite transpiler (Babel, Traceur, etc.) to compile your code to ES5 and use it with the rest of the code from the tutorial, but I suppose you already have that running.