我编写了代码,以在屏幕尺寸较小时加载其他模板。在Angular 4中运行正常。现在升级到Angular 6后,它抛出错误:
ERROR in ./src/app/student/student.component.ts
Module not found: Error: Can't resolve ' ""+((window.innerWidth) > 745 ?
"student.component.html" :
"student.component.mobile.html")' in 'C:\BIT_BUCKET\STUDENT\STUDENT-WEB\src\app\student'
代码:
@Component({
selector: 'app-lineside-inspection',
templateUrl: "./"+((window.innerWidth) > 745 ?
"student.component.html" :
"student.component.mobile.html"),
styleUrls: ['./student.component.css']
})
版本:
Angular CLI: 6.0.8
Node: 9.8.0
OS: win32 x64
Angular: 6.0.7
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.6.8
@angular-devkit/build-angular 0.6.8
@angular-devkit/build-optimizer 0.6.8
@angular-devkit/core 0.6.8
@angular-devkit/schematics 0.6.8
@angular/cdk 6.3.2
@angular/cli 6.0.8
@angular/material 6.3.2
@ngtools/webpack 6.0.8
@schematics/angular 0.6.8
@schematics/update 0.6.8
rxjs 6.2.1
typescript 2.7.2
webpack 4.8.3
答案 0 :(得分:0)
我认为您将无法执行这样的操作。但是我宁愿建议将两个html内容都放在一个文件中,并使用* ngIf指令。就是这样。
或者如果您确实要使用两个html页面,则可以使用选择器。
就像是,
<second-html-component *ngIf = "condition"></second-html-component>