【发布时间】:2021-02-18 14:13:37
【问题描述】:
我目前正在关注这个教程:https://www.youtube.com/watch?v=WlAq06Z_25Y&list=PL8p2I9GklV45JZerGMvw5JVxPSxCg8VPv&index=4
但html只显示
我正在尝试学习 Angular,但是如果您尝试跟随 turturial 但有些事情就是不匹配,这会非常令人困惑
代码:
app.module.ts 代码:
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'blog';
}
app.component.html 代码:
<h1>Hello World !</h1>
<h2>{{title}}</h2>
app.component.spec.ts 代码:
import { TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { AppComponent } from './app.component';
describe('AppComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
RouterTestingModule
],
declarations: [
AppComponent
],
}).compileComponents();
});
it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});
it(`should have as title 'blog'`, () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app.title).toEqual('blog');
});
it('should render title', () => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.nativeElement;
expect(compiled.querySelector('.content span').textContent).toContain('blog app is running!');
});
});
【问题讨论】:
-
控制台有错误吗?
-
分享你的component.ts和component.html
-
请显示您正在尝试的代码。
-
你在哪里打开应用程序?如果您直接在浏览器中打开 .html 文件,显然它将按原样呈现。 Angular 应用程序应该由服务器提供。如果您使用
ng serve测试应用程序,默认情况下它在http://localhost:4200中提供。您需要打开此 URL 而不是直接打开文件。 -
另外,如果你是新手,我强烈建议你去他们的official tutorial。它相当简短,介绍了框架的许多基础知识。
标签: javascript html angular