HTML code only shows {{title}} instead of variable name

I’m currently following this tuturial: https://www.youtube.com/watch?v=WlAq06Z_25Y&list=PL8p2I9GklV45JZerGMvw5JVxPSxCg8VPv&index=4

what i want

but html only shows

what i get:

i’m trying to learn angular but it’s verry confusing if you try to follow a turturial but some things just dont match up

code:

app.module.ts code:

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 code:

<h1>Hello World !</h1>
<h2>{{title}}</h2>

app.component.spec.ts code:

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!');
  });
});

94 thoughts on “HTML code only shows {{title}} instead of variable name”

  1. You need to run your app with ng serve and then verify your output on localhost:4200.
    In case you need to run it on any other port, use ng serve --port:portnumber

    Reply
  2. Try creating a public method to pass it between your components:

    export class AppComponent {
      public title = "blog";
    }
    
    <h2>{{ title }}</h2>
    
    Reply

Leave a Comment