我有一个angular 2应用程序,我没有使用angular-cli来生成它。我是Angular的新手,我正在尝试让我的应用程序与IE,旧的Safari等一起工作。
我读了很多关于polyfills.ts的文章,我如何将它添加到我的angular 2应用程序中(我正在使用systemjs加载该应用程序)
下面是我目前正在加载的脚本:
<script src = "node_modules/core-js/client/shim.min.js"></script>
<script src = "node_modules/zone.js/dist/zone.js"></script>
<script src = "node_modules/reflect-metadata/Reflect.js" ></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>和systemjs.config:
(function (global) {
System.config({
paths: {
// paths serve as alias
'npm:': '/node_modules/'
},
// map tells the System loader where to look for things
map: {
// our app is within the app folder
app: '/js/angular/eventticketspage',
// angular bundles
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
// other libraries
'rxjs': 'npm:rxjs',
'core-js': 'npm:core-js'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: {
main: './main.js',
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
},
'core-js': {
defaultExtension: 'js'
}
}
});
})(this);编辑:我可以通过添加脚本来解析未定义的'intl‘:
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=Intl.~locale.en"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/classlist/2014.01.31/classList.min.js"></script>但是我想用正确的方式来做,使用Polyfills.ts
发布于 2017-05-31 14:33:57
看起来你只需要手动完成。根本就没有魔法。我刚刚从https://github.com/angular/angular/blob/master/aio/src/polyfills.ts复制了polyfills.ts,并将其包含在我的源代码文件夹中。我已经取消了对IE的注释,但离开了区域,并将反射行注释掉了。然后在我的应用程序中
import "../shared/pollyfills" // I have put pollyfills.ts in a shared folder
import "zone.js";
import "reflect-metadata";它导入核心文件,该文件又导入pollyfills.ts -js/es6包。
虽然我使用的是一个模块捆绑器,所以我不确定system.js是如何工作的--但是原理是一样的,复制pollyfills文件并像导入其他模块一样导入它。哦,当然,在你的package.json中你需要
"core-js": "^2.4.1",或者类似的。
https://stackoverflow.com/questions/44270659
复制相似问题