在angular2.0中进行页面刷新时,页面显示一个意外的错误标记<;
我使用angular 2.0重新加载页面时出错。因为它采用了一个错误的路径来获取像css和javascript文件这样的文件,实际上是根文件夹中的css,但是它被认为与index.html/styles.css一样错误,请注意下面的示例代码和错误 System.config.js在angular2.0中进行页面刷新时,页面显示一个意外的错误标记<;,angular,typescript,Angular,Typescript,我使用angular 2.0重新加载页面时出错。因为它采用了一个错误的路径来获取像css和javascript文件这样的文件,实际上是根文件夹中的css,但是它被认为与index.html/styles.css一样错误,请注意下面的示例代码和错误 System.config.js (function (global) { System.config({ // DEMO ONLY! REAL CODE SHOULD NOT TRANSPILE IN THE BROWSER transpiler:
(function (global) {
System.config({
// DEMO ONLY! REAL CODE SHOULD NOT TRANSPILE IN THE BROWSER
transpiler: 'ts',
typescriptOptions: {
tsconfig: true
},
meta: {
'typescript': {
"exports": "ts"
}
},
paths: {
// paths serve as alias
'npm:': 'https://unpkg.com/'
},
// map tells the System loader where to look for things
map: {
// our app is within the app folder
app: 'app',
// 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',
'@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js',
// other libraries
'rxjs': 'npm:rxjs',
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api',
'ts': 'npm:plugin-typescript@4.0.10/lib/plugin.js',
'typescript': 'npm:typescript@2.0.2/lib/typescript.js',
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: {
main: './main.ts',
defaultExtension: 'ts'
},
rxjs: {
defaultExtension: 'js'
},
'angular-in-memory-web-api': {
main: './index.js',
defaultExtension: 'js'
}
}
});})(this);
index.html
<!DOCTYPE html>
document.write(“”);
英雄之旅
System.import('app').catch(函数(err){console.error(err);});
加载。。。
在web浏览器中进入控制台时出现以下错误
获取~URL/angular2/index.html/styles.css获取~URL/angular2/index.html/systemjs.config.js 获取~URL/angular2/index.html/systemjs.config.js
错误:SyntaxError:意外标记如何为这些文件提供服务?您确定您的服务器正确地提供文件吗?在单页应用程序中提供index.html而不是js文件是一个常见问题。:)您使用什么web服务器进行此操作?
<script>document.write('<base href="' + document.location + '" />');</script>
<title>Angular Tour of Heroes</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles.css">
<!-- Polyfill(s) for older browsers -->
<script src="https://unpkg.com/core-js/client/shim.min.js"></script>
<script src="https://unpkg.com/zone.js@0.6.25?main=browser"></script>
<script src="https://unpkg.com/reflect-metadata@0.1.3"></script>
<script src="https://unpkg.com/systemjs@0.19.27/dist/system.src.js"></script>
<script src="systemjs.config.js"></script>
<script>
System.import('app').catch(function(err){ console.error(err); });
</script>
<body>
<my-app>Loading...</my-app>
</body>
</html>