未捕获的ReferenceError:未定义系统

编程入门 行业动态 更新时间:2024-10-11 09:25:52
未捕获的ReferenceError:未定义系统 - Angular2(Uncaught ReferenceError: System is not defined - Angular2)

index.html页面在屏幕上加载并显示加载。 但是,我没有看到我在app.component.ts的模板属性中定义的文本“我的第一个组件”。 当我使用F12打开开发人员工具时,我看到错误:

未捕获的ReferenceError:未定义系统。

它指向app.component.js文件中的第一行。 有人能告诉我问题是什么吗?

app.component.ts

import { Component } from '@angular/core'; @Component({ selector: 'pm-app', template: ` <div> <h1>{{pageTitle}}</h1> <div> My First Component </div> </div> ` }) export class AppComponent { pageTitle: string = 'Hello World'; }

tsconfig.json

{ "compilerOptions": { "target": "ES5", "module": "system", "sourceMap": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "moduleResolution": "node", "removeComments": false, "noImplicitAny": true, "suppressImplicitAnyIndexErrors": true }, "exclude": [ "node_modules" ] }

的index.html

<!DOCTYPE html> <html> <head> <title>Angular 2 Application</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="app/app.component.css" rel="stylesheet" /> <!-- 1. Load libraries --> <!-- IE required polyfills, in this exact order --> <script src="node_modules/es6-shim/es6-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/rxjs/bundles/Rx.umd.js"></script> <script src="node_modules/@angular/core/core.umd.js"></script> <script src="node_modules/@angular/common/common.umd.js"></script> <script src="node_modules/@angular/compiler/compiler.umd.js"></script> <script src="node_modules/@angular/platform-browser/platform-browser.umd.js"></script> <script src="node_modules/@angular/platform-browser-dynamic/platform-browser-dynamic.umd.js"></script> <script src='app/app.component.js'></script> <script src='app/main.js'></script> <script src="node_modules/systemjs/dist/system.src.js"></script> <!-- 2. Configure SystemJS --> <script> System.config({ packages: { app: { format: 'register', defaultExtension: 'js' } } }); System.import('app/main') .then(null, console.error.bind(console)); </script> </head> <body> <pm-app>Loading..</pm-app> </body> </html>

main.ts

import { bootstrap } from '@angular/platform-browser-dynamic'; // Our main component import { AppComponent } from './app.component'; bootstrap(AppComponent);

The index.html page loads on the screen and shows loading. However I don't see the text "My First Component " which i have defined in the template attribute of app.component.ts. When I do a F12 to open up developer tools , I see error:

Uncaught ReferenceError: System is not defined.

It points to the first line in the app.component.js file. Can somebody tell me what the problem is ?

app.component.ts

import { Component } from '@angular/core'; @Component({ selector: 'pm-app', template: ` <div> <h1>{{pageTitle}}</h1> <div> My First Component </div> </div> ` }) export class AppComponent { pageTitle: string = 'Hello World'; }

tsconfig.json

{ "compilerOptions": { "target": "ES5", "module": "system", "sourceMap": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "moduleResolution": "node", "removeComments": false, "noImplicitAny": true, "suppressImplicitAnyIndexErrors": true }, "exclude": [ "node_modules" ] }

index.html

<!DOCTYPE html> <html> <head> <title>Angular 2 Application</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="app/app.component.css" rel="stylesheet" /> <!-- 1. Load libraries --> <!-- IE required polyfills, in this exact order --> <script src="node_modules/es6-shim/es6-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/rxjs/bundles/Rx.umd.js"></script> <script src="node_modules/@angular/core/core.umd.js"></script> <script src="node_modules/@angular/common/common.umd.js"></script> <script src="node_modules/@angular/compiler/compiler.umd.js"></script> <script src="node_modules/@angular/platform-browser/platform-browser.umd.js"></script> <script src="node_modules/@angular/platform-browser-dynamic/platform-browser-dynamic.umd.js"></script> <script src='app/app.component.js'></script> <script src='app/main.js'></script> <script src="node_modules/systemjs/dist/system.src.js"></script> <!-- 2. Configure SystemJS --> <script> System.config({ packages: { app: { format: 'register', defaultExtension: 'js' } } }); System.import('app/main') .then(null, console.error.bind(console)); </script> </head> <body> <pm-app>Loading..</pm-app> </body> </html>

main.ts

import { bootstrap } from '@angular/platform-browser-dynamic'; // Our main component import { AppComponent } from './app.component'; bootstrap(AppComponent);

最满意答案

试着移动

<script src="node_modules/systemjs/dist/system.src.js"></script>

在您的rxjs脚本声明之上

Try moving

<script src="node_modules/systemjs/dist/system.src.js"></script>

above your rxjs script declaration

更多推荐

本文发布于:2023-08-02 09:48:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1372719.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:未定义   系统   ReferenceError

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!