在我的组件中,我想使用 require 设置 templateUrl,如下所示:
import {Component} from 'angular2/core';
@Component({
selector: 'header',
styleUrls: ['app/header/header.css'],
templateUrl: require('./hahaha.html')
})
export class HeaderComponent {
logoUrl: string = '/resources/img/branding.png';
constructor () {
}
}
在我的控制台中,我收到错误
angular2-polyfills.js:332 错误: TypeError: require 不是函数
在评估时(http://localhost:3000/app/header/header.js:29:35 http://localhost:3000/app/header/header.js:29:35)
在执行时(http://localhost:3000/app/header/header.js:34:14 http://localhost:3000/app/header/header.js:34:14) 错误加载http://localhost:3000/app/main.js http://localhost:3000/app/main.js
我希望能够做这样的事情:(我确实知道解决方法,但我只是想了解更多,如何以其他方式使其工作)
// Note that this is a relative path, which I will get error for now, I have to write from root path, don't like it.
styleUrls: ['./header.css']
templateUrl: require('./hahaha.html')
这是我的 tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules",
"typings/main",
"typings/main.d.ts"
]
}