今日、コンポネントの定義の仕方を知りました。
それが二つありました。
一つ目が
const htmlStr: string = require('component/reporthistory.component.html'); const cssStr: string = require("component/reporthistory.component.css"); const cssNav: string = require("../assets/css/navBar.css"); @Component({ selector: 'report-history', template: htmlStr, styles: [cssStr, cssNav], pipes: [I18nDatePipe] })
二つ目が
@Component({ selector: 'report-history', template: 'component/reporthistory.component.html', styles: ["component/reporthistory.component.css", "../assets/css/navBar.css"], pipes: [I18nDatePipe] })
一つ目が定数で受け取って、templateとstylesに渡しているパターンです。
後者のような例はたくさん見つけました。
前者のように、require()を使うメリットはなんですか?
パスが存在しなかったときに、エラーが出るとかですかね。
まったく分かりません。
教えてください。
あなたの回答
tips
プレビュー