【发布时间】:2017-09-24 02:24:30
【问题描述】:
我对 Angular 2 很陌生,所以请多多包涵。 我试图让一个新组件出现在 index.html 页面中。 该文件集来自 GitHub 的基本快速入门文件。 我这样创建了一个新组件:
import { Component } from '@angular/core';
@Component({
selector: 'app-user-item',
template: `<h1>It works!</h1>`,
})
export class UserItemComponent {
}
我已经在 HTML 中声明了选择器标签:
<!DOCTYPE html>
<html>
<head>
<title>Angular QuickStart</title>
<base href="/">
<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="node_modules/core-js/client/shim.min.js"></script>
<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="systemjs.config.js"></script>
<script>
System.import('main.js').catch(function(err){ console.error(err); });
</script>
</head>
<body>
<my-app>Loading AppComponent content here ...</my-app>
<app-user-item>loading another component</app-user-item>
</body>
</html>
我什至尝试将导入添加到 app.module.ts 的顶部,并将组件名称添加到 app.module.ts 中的声明数组。但还是一无所获。 我检查了我的文件结构,并且有一个 js 版本的 user-item.component.ts。但我看不到变化。
任何帮助将不胜感激。
干杯
【问题讨论】: