有没有办法在没有任何模块加载器的情况下使用angular 2? [英] Is there a way to use angular 2 without any module loader?

查看:69
本文介绍了有没有办法在没有任何模块加载器的情况下使用angular 2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

angular 2官方网站上的快速入门"部分介绍了如何运行最简单的angular 2应用程序.默认情况下, SystemJS 用作模块加载器.也有一条注释,说有替代方法也可以.我了解模块加载程序的好处,但是有没有一种方法可以完全不使用任何模块加载程序来运行angular 2应用程序?

The Quickstart section on the angular 2 official site describes how to run the simpliest angular 2 application. By default SystemJS is used as module loader. Also there is a note, saying that there are alternatives that work just fine. I understand the benefits of module loaders, but is there a way to run angular 2 app without any module loader at all?

当我简单地删除SystemJS配置和SystemJS源脚本标记时,在控制台中的angular2.dev.js文件中出现错误:

When I simply delete SystemJS configuration and SystemJS source script tag, I get an error in console in angular2.dev.js file:

Uncaught ReferenceError: System is not defined

似乎angular 2本身使用SystemJS.那么,有没有办法在没有任何模块加载器的情况下使用angular 2?

It looks like angular 2 itself uses SystemJS. So, is there a way to use angular 2 without any module loader?

推荐答案

是的,您可以使用普通的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.

这篇关于有没有办法在没有任何模块加载器的情况下使用angular 2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆