【问题标题】:Is there any difference between using require of node in template and templateUrl in Angular 2在模板中使用 node 的 require 和在 Angular 2 中使用 templateUrl 有什么区别吗
【发布时间】:2018-09-08 01:18:30
【问题描述】:

使用有什么区别

  1. require 来自模板中的节点
  2. templateUrl 在 Angular 2 中

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

【问题讨论】:

    标签: angular angular2-template require


    【解决方案1】:

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

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

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

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

    不同之处在于template 仅用于小模板,templateUrl 用于文件。

    【讨论】:

    • 我知道template和templateUrl的区别。问题是为什么要在模板中使用 Node 的 require 关键字?
    • 这就是我目前正在做的事情,但对我来说仍然很困惑。
    猜你喜欢
    • 1970-01-01
    • 2017-04-24
    • 2016-07-25
    • 2016-02-18
    • 2017-09-21
    • 1970-01-01
    • 1970-01-01
    • 2017-05-20
    • 1970-01-01
    相关资源
    最近更新 更多