我正在学习制作一个简单的均值堆栈应用程序。我在角度项目中创建了一个组件。在index.html中用
编写的文本通过节点服务器显示正常,但不是我创建的组件。我应该如何通过Express部署完整的角度应用程序?
app.component.html:
<router-outlet></router-outlet>
comp.component.html:
<p>comp works!</p>
index.html:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>App</title>
<base href="/">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<p>usama</p>
<app-root></app-root>
<app-comp></app-comp>
</body>
</html>
server.js:
const express =require('express');
const app=express();
var path = require("path");
app.get('/',function(req,res){
res.sendFile(__dirname + '/index.html');
});
const port=process.env.port || 3000;
app.listen(port,()=>console.log('Listening to port '+ port));
app.routing.module.ts:
import { NgModule } from '@angular/core';
import { Routes,RouterModule } from '@angular/router';
import { CompComponent } from './comp/comp.component';
const routes: Routes = [
{path:'comp',component:CompComponent}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],exports: [RouterModule]
})
export class AppRoutingModule { }