使用模板中的节点和Angular 2中的templateUrl之间有什么区别吗?

问题描述 投票:0回答:1

使用之间有什么区别吗?

  1. require来自模板中的节点
  2. 角色2中的templateUrl @Component({ selector: 'hello', template: require('./home.html'), }) @Component({ selector: 'hello', templateUrl: './hello.html', })
angular angular2-template require
1个回答
0
投票

使用template属性可以在javascript文件中定义html模板。这可以用于小模板。

@Component({
    selector: 'hello',
    template: `<h1>This is part of template`
})

templateUrl加载./hello.html文件使用它代替模板。

@Component({
    selector: 'hello',
    templateUrl: './hello.html',
})

不同的是使用template只是小模板和templateUrl文件。

© www.soinside.com 2019 - 2024. All rights reserved.