我遵循位于以下位置的模板和样式指南的组件相对路径:
https://angular.io/docs/ts/latest/cookbook/component-relative-paths.html
该指南建议,如果我们将应用程序构建为commonjs模块,并使用合适的包加载器(如systemjs )加载这些模块,则可以指定相对于其组件类文件的模板和样式位置。
我们所需要做的就是将组件模板和特定于组件的样式文件作为它们的配套组件类文件的兄弟文件。采用了这种文件结构约定后,我们可以简单地通过设置@Component元数据的moduleId属性来指定模板和样式文件相对于组件类文件的位置,如下所示
@Component({
moduleId: module.id,
selector: 'relative-path',
templateUrl: 'some.component.html',
styleUrls: ['some.component.css']
})我使用的是Visual Studio2015 TypeScript 2.0测试版,下面是我的tsconfig文件:
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"module": "commonjs",
"moduleResolution": "node",
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": false,
"target": "es5",
"outDir": "../content/app/"
},
"exclude": [
"node_modules",
"typings/main",
"typings/main.d.ts"
]
}但是当我试图编译我的项目时,它不能识别@Component元数据中的module.id,并抛出错误:
Severity Code Description Project File Line Suppression State
Error Build:Cannot find name 'module'.有人能指导一下如何修复这个问题吗?
发布于 2016-08-26 05:14:11
您可以通过在typings.d.ts文件中包含以下内容来修复它。
declare var module: { id: string };希望这能有所帮助!!
发布于 2017-01-13 05:08:19
前面的建议答案是:declare var module: { id: string };
这不应该是必要的。这一点和你的tsconfig表明你正在使用旧的配置。几个月前,我们停止使用typings,转而使用npm加载它们。您应该在package.json中看到如下所示的内容
知道你是在使用"devDependencies": { "@types/angular": "^1.5.16", "@types/angular-animate": "^1.5.5", "@types/angular-cookies": "^1.4.2", "@types/angular-mocks": "^1.5.5", "@types/angular-resource": "^1.5.6", "@types/angular-route": "^1.3.2", "@types/angular-sanitize": "^1.3.3", "@types/jasmine": "~2.5.36", "@types/node": "^6.0.45", ...还是systemjs也很重要。如果这是一个问题,我将在稍后解释。
https://stackoverflow.com/questions/39154798
复制相似问题