【发布时间】:2018-03-05 20:30:30
【问题描述】:
我正在学习 Angular,并且有一个简单的项目(单页网页),通过 Firebase 链接并成功托管。
问题是,虽然我在本地提供页面时可以很好地查看页面(在目录中提供 ng 服务),但当我提供它或将其部署到 Firebase 时,它只呈现 HTML(而不是链接到的内容)角度分量)。
目录文件结构图: Hosting under src file, firebase.json file at the same level as angular-cli.json
index.html:
</head>
<body>
<h1>NORMAL HTML!</h1>
<app-root></app-root>
<h1>THERE SHOULD BE SOME STUFF ABOVE ME!</h1>
app.component.ts 是标准组件:
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app works!';
}
app.component.html:
<h1>
{{title}}
</h1>
app.module.ts:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { RouterModule } from '@angular/router';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
AppRoutingModule,
RouterModule,
],
providers: [AppRoutingModule],
bootstrap: [AppComponent]
})
export class AppModule { }
app-routing.module.ts:
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
const routes: Routes = [
{
path: '',
component: AppComponent,
pathMatch: 'full'
}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule],
providers: []
})
export class AppRoutingModule { }
main.ts:
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { environment } from './environments/environment';
import { AppModule } from './app/app.module';
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule);
firebase.json:
{
"hosting": {
"public": "src"
}
}
.firebaserc:
{
"projects": {
"default": "alicespyglass-tinker"
}
}
我被难住了。
【问题讨论】: