0

Please help me with this error when coding with Typescript in Sublime and VS Code. It can only be recognized and correctly display in browser if all template: code is in one single line.

template:'<h1>{{title}}</h1><h2>{{hero.name}} details!</h2><div><label>id: </label>{{hero.id}}</div><div><label>name: </label>{{hero.name}}</div>',

When I try to break it down to serveral lines, the browser cannot display the result as expected.

Below is the full code of what I'm doing:

import { Component } from '@angular/core';

export class Hero {
    id: number;
    name: string;
}

@Component({
    selector: 'my-app',
    template:'<h1>{{title}}</h1><h2>{{hero.name}} details!</h2><div><label>id: </label>{{hero.id}}</div><div><label>name: </label>{{hero.name}}</div>',
})

export class AppComponent {
    title = 'Tour of Heroes';
    hero = Hero {
        id: 1;
        name: 'Windstorm';
    }   
}

This tutorial is from angular.io

0

1 Answer 1

3

You need to use backticks when writing multi lines

@Component({
    template: `
        //code here
    `
})

Use templates with large amounts of HTML.

@Component({
    templateUrl: "PATH HERE"
})

Hope that helps

Sign up to request clarification or add additional context in comments.

1 Comment

My bad! missed out on that from the tutorial.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.