Angular 2 allows to write multi-line templates by using ` characters to enquote them. It is also possible to put multi-line template into .html
file and reference it by templateUrl
.
It seems comfortable for me to put the template directly into component as then it's all in one place, but is there any drawback of doing so?
1st approach:
import {Component} from 'angular2/core';
@Component({
selector: 'my-app',
template: `
<h1>My First Angular 2 multiline template</h1>
<p>Second line</p>
`
})
export class AppComponent { }
vs
2nd approach:
import {Component} from 'angular2/core';
@Component({
selector: 'my-app',
templateUrl: 'multi-line.html'
})
export class AppComponent { }
together with multi-line.html
:
<h1>My First Angular 2 multiline template</h1>
<p>Second line</p>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…