1

I am getting spacing issue with the template field in Angular2

This is my code.

@Component({
    selector: 'my-component',
    template: ' <h1 class="test">
                   Angular 2 Template    
                </h1>',
    styleUrls: ['./assets/style.css']
})

This does not work

@Component({
    selector: 'my-component',
    template: ' <h1 class="test">Angular 2 Template</h1>',
    styleUrls: ['./assets/style.css']
})

This works

Robin-Hoodie
  • 4,886
  • 4
  • 30
  • 63

1 Answers1

1

That's because you should use the ES6 backtick "`" for template literals:

Component({
        selector: 'my-component',
        template: ` <h1 class="test">
                       Angular 2 Template    
                    </h1>`,
        styleUrls: ['./assets/style.css']
    })
Robin-Hoodie
  • 4,886
  • 4
  • 30
  • 63