我是初学者,我正在尝试用角度创建一个简单的组件,但是我有问题,我的组件没有显示在索引页面中,请帮助我。
这是我的具有"List.Component.ts“名称的组件:
import { Component } from '@angular/core';
@Component({
selector:'navBar',
templateUrl:'./navBarTemplate.html'
})
export class navBar {
constructor(){
}
}这是我的模板html代码:
<ul>
<li>Test-1</li>
<li>Test-2</li>
<li>Test-3</li>
</ul>我在"app.module.ts“文件中导入了组件:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
//here is my component
import { navBar } from './List.Component';
@NgModule({
imports: [ BrowserModule ],
declarations: [ AppComponent, navBar ],
bootstrap: [ AppComponent ]
})
export class AppModule { }但是角只是在索引页面中显示了"Hello角“。
我的索引页:
<!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>
<NavBar></NavBar>
<my-app>Loading AppComponent content here ...</my-app>
</body>
</html>发布于 2019-12-20 11:45:54
<body>
<NavBar></NavBar>
<my-app>Loading AppComponent content here ...</my-app>
</body>整个应用程序都封装在my-app中。它的外部部分不知道<navBar>是什么,除非在其他地方声明和编译web组件。
简单地说,您需要将<navBar> (注意初始n小写)封装在中--中的任何组件中--您的角度应用程序。例如,您可以将它放置在AppComponent中,这很可能是您希望它出现的地方。
发布于 2019-12-20 11:44:22
您需要在<NavBar></NavBar>中添加app.component.html
发布于 2019-12-20 11:45:24
在index.html文件中,删除导航条选择器,并在app.component.html文件中使用下面的导航条选择器
<navBar></navBar>https://stackoverflow.com/questions/59424733
复制相似问题