角度1.5のコンポーネントでtypescriptを使用しています。そして、私はrequire経由でテンプレートを送るカスタムデザインのデコレータを持っています。私はtslintの警告を得る以外は動作します。 (私はこのルールをオフにしたくない)テンプレートを必要とせずにタイプスクリプトにインポート
必要()形式のインポートはここ
を禁止されている私のコンポーネントは
import './main.template.html';
const app: ng.IModule = angular.module('app');
@Component(app, {
selector: 'mainComponent',
controllerAs: 'ctrl',
styleUrls: '',
template: require('./main.template.html')
})
class MainComponent extends BaseComponent {
constructor() {
super();
}
}
であるここに私のデコレータは
export const Component = function(module: ng.IModule, options: {
selector: string,
controllerAs?: string,
styleUrls?: string,
template?: string,
templateUrl?: string
}) {
return (controller: Function) => {
module.component(options.selector, angular.extend(options, { controller: controller }));
};
};
です
テンプレートの代わりにtemplateUrlを渡そうとしましたが、ファイルの実行時エラーが見つかりません。
私は変数としてテンプレートをインポートしようとしましたが、コンパイル時にエラーが発生し、サポートされていないようです。
import mytemplate: string from './main.template.html';
私はwebpackを使用しています。したがって、ルートから絶対パスを使用することはできません。
requireスクリプトを使用せずにtypescriptでテンプレートをインポートする方法はありますか?
私はWebPACKの構築、したがって何のテンプレートファイルやディレクトリ構造がありません使用していますテンプレート –