什么'Angular2-all.umd.js和Angular2.js之间的区别
What's the difference between Angular2-all.umd.js and angular2.js
此时Angular 2正处于第13个测试阶段。当我看着https://code.angularjs.org/2.0.0-beta.13/我可以看到Angular2:有两个不同的版本
- angular2-all.umd.js
- angular2.js
两者之间有什么区别?显然angular2.js没有angular2.umd.js版本,为什么是这样?
事实上,如果您想用ES5实现Angular2应用程序,就必须使用angular2-all.umd.js
。
angular2.js
是使用ES6或TypeScript实现Angular2应用程序的核心模块。此文件必须与SystemJS等模块管理器一起使用。
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>
如上所述,ES5应该使用UMD模块:angular2-all.umd.js
和Rx.umd.js
。对于Typescript或ES6,请使用angular2.js
和Rx.js
(它们还需要system.js
)。
作为一种教育练习,还可以将ES6风格的模块与ES5一起使用:(https://jsfiddle.net/8g5809rg/)
<html>
<head>
<script src="https://code.angularjs.org/tools/system.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.13/Rx.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.13/angular2-polyfills.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.13/angular2.js"></script>
<script>
System.import("angular2/core").then(function(core) {
ParentComponent.annotations = [
new core.Component({
selector: 'body',
template: '<div (click)="go()">Parent</div><child [prop1]="x"></child>',
directives: [ChildComponent]
})
];
function ParentComponent() {
this.x = "hello1"
}
ParentComponent.prototype.go = function() {
this.x += "1"
};
///
ChildComponent.annotations = [
new core.Component({
selector: 'child',
inputs: ["prop1"],
template: '<div>Child {{prop1}}</div>',
changeDetection: core.ChangeDetectionStrategy.OnPush
})
];
function ChildComponent() {
}
////////////////
System.import("angular2/platform/browser").then(function(browser) {
document.addEventListener('DOMContentLoaded', function() {
browser.bootstrap(ParentComponent);
});
});
});
</script>
</head>
<body>
</body>
</html>
相关文章:
- 如何将此JS翻译成Angular2
- 什么'Angular2-all.umd.js和Angular2.js之间的区别
- 如何将 jquery 和其他.js库与 Angular2 一起使用
- traverson.js集成到Angular2应用程序中
- Angular2 英雄示例在与节点.js服务器结合使用时使 POST 翻倍
- 我不知道如何在angular2中包含js文件并使用jquery
- Angular2 System.js可以'找不到jspm包
- PHP哈希值('sha512',$x)在Node.js (Angular2, Ionic2)中等效
- Angular2 + ag-Grid无法加载ag-Grid -ng2/main.js (404 Not Found)
- Angular2无法更新到RC7 - zone.js &reflect-metadata
- 未捕获的[对象对象]被抛出- zone.js"模拟响应(Angular2)时抛出错误
- Angular2 RC5导入第三方JS库:摊牌
- Angular2 rc6 - systemjs.config.js使用子文件夹/src/app
- 如何在Angular2应用中使用SystemJS加载bootstrap.js、jQuery和其他模块
- angular2项目、Js和Html的捆绑和压缩
- Angular2/Node.js应用无法在ie浏览器中加载
- 错误:ENOENT:没有Angular2和Express.js这样的文件或目录
- ForBiddenError in Node.js/Express.js/Angular2
- 无法在Angular2和Express.js中获取/
- 如何在Angular2项目中将moment.js实现为管道