Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 如何为SystemJS和Webpack编写angular 2组件模板url的单个url?_Angularjs_Webpack_Systemjs - Fatal编程技术网

Angularjs 如何为SystemJS和Webpack编写angular 2组件模板url的单个url?

Angularjs 如何为SystemJS和Webpack编写angular 2组件模板url的单个url?,angularjs,webpack,systemjs,Angularjs,Webpack,Systemjs,我发现对于SystemJS和Angular2@Component templateUrls中的Webpack项目构建,字符串必须不同 对于SystemJS: @Component({ selector: 'home' templateUrl: './app/home/home.component.html' }) export class HomeComponent implements OnInit, OnDestroy { ... } 对于网页包: @Compone

我发现对于
SystemJS
Angular2@Component templateUrls中的Webpack项目构建,字符串必须不同

对于SystemJS:

@Component({
    selector: 'home'
    templateUrl: './app/home/home.component.html'
})
export class HomeComponent implements OnInit, OnDestroy {
    ...
}
对于网页包:

@Component({
    selector: 'home'
    templateUrl: './home.component.html'
})
export class HomeComponent implements OnInit, OnDestroy {
    ...
}
对于
SystemJS
build
templateUrl
string必须是根目录下的完整路径。对于
Webpack
templateUrl
必须是来自根目录的非完整路径(组件和组件说明的html模板
*.ts
文件位于一个位置)。可以为
SystemJS
Webpack
编写单个模板URL字符串?对于mutch快速切换,请参见
SystemJS/Webpack
。我尝试将变量字符串用于
模板URL

import { loginComponentTemplateUrl } from '../shared/url-routing-provider';

@Component({
    templateUrl: loginComponentTemplateUrl 
})
url路由提供程序.ts

export var systemjs: boolean = true;
export var loginComponentTemplateUrl: string = (systemjs) ? './login.component.html' : './app/login/login.component.html';
export default systemjs;

对于
SystemJS
它可以工作(对于AMD模式),但对于
Webpack
则不行。我的previos帖子与此相关:

要使用systemJs模块加载器的相对路径,您可以。然而,当您切换到使用数字模块标识符的webpack时,此技巧不起作用

适用于网页包和system.js的解决方案:

@Component({
   moduleId: typeof module.id == "string" ? module.id : null,
   selector: 'home'
   templateUrl: './home.component.html'
})
export class HomeComponent implements OnInit, OnDestroy {
  ...
}
它很管用,但我看不出它漂亮