在Angular 2组件中设置moduleId不起作用

时间:2016-12-08 05:53:48

标签: angular relative-path

我试图在Angular 2中设置相对路径,如Angular 2文档的COMPONENT-RELATIVE PATHS部分所述。在我的组件中,我在装饰器中设置了moduleId

@Component({
    selector: 'SpecifiedInsuredExtra',
    moduleId: module.id, 
    templateUrl: './Templates/SpecifiedInsuredExtra-1.0.2.html',
    providers: [SpecifiedInsuredExtraService]
})

我的tsconfig.json将模块设置为commonjs

{
    "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false,
    "outDir": "Angular/Transpiled/"
  },
  "compileOnSave": true,
  "exclude": [
      "node_modules",
      "wwwroot"
  ]
}

然后我使用gulp任务来缩小我的组件js文件

gulp.task('SpecifiedInsuredExtraAngularJs', ["CleanSpecifiedInsuredExtraJs"], function () {
    util.log('Creating specifiedinsuredextra-1.0.2.min.js.');

    var builder = new Builder('', './Angular/Configurations/SpecifiedInsuredExtraConfiguration.js');

    return builder
    .buildStatic(paths.transpiled + '/Applications/SpecifiedInsuredExtra.js', paths.scripts + 'specifiedinsuredextra-1.0.2.min.js', { minify: true, sourceMaps: true })
    .then(function () {
        console.log('Build complete');
    })
    .catch(function (err) {
        console.log('Build error');
        console.log(err);
    });
});

gulp.task('SpecifiedInsuredExtraJs', ["SpecifiedInsuredExtraAngularJs"], function () {
    util.log('Creating specifiedinsuredextra-1.0.2.min.js.');

    return gulp.src(
    [
        './wwwroot/Scripts/specifiedinsuredextra.min.js'
    ])
    .pipe(concat('specifiedinsuredextra-1.0.2.min.js'))
    .pipe(uglify()).pipe(gulp.dest(paths.scripts));
});

据我所知,重新启动路径现在应该有效,但是当我运行应用程序时,我得到404 http response,因为在应用程序的根目录中找不到模板。当我将module对象记录到控制台时,id设置为13,我希望将其设置为相对路径

enter image description here

我有什么东西在这里失踪吗?

0 个答案:

没有答案