我有以下代码
import { Component, OnInit } from '@angular/core';
import { mobile } from '../../../../environments/environment';
@Component({
selector: 'ctk-details-advisory',
templateUrl: (mobile) ? 'details-advisory.component.mobile.html' :
'details-advisory.component.html',
styleUrls: ['./details-advisory.component.scss'],
})
export class DetailsAdvisoryComponent implements OnInit {
// ...这帮助我控制不同的html,个人电脑和移动视图。问题是,当我想要执行单元测试时,我会得到以下错误
找不到模块:错误:无法解决‘(移动)?'/home/anonymous/criptoanalisis-0.2/frontend/src/app/pages/advisory/details-advisory‘@ ./src/app/pages/advisory/details-advisory/details-advisory.component.ts 23:22-121中的’details-Advisory.Component.html‘
这对解决这个问题有很大的帮助,或者控制不同html的另一种方法。事实上,我正努力解决这个问题,我非常感激任何建议。
发布于 2018-12-25 06:06:53
使用单个html (details-advisory.component.html),而不是使用两个不同的模板(一个单独用于移动)。在component代码中,定义一个类成员
public isMobile = mobile; // imported from the environment in the import section然后,在template html代码中,可以使用
<ng-container *ngIf="isMobile; else desktopView">
// all html related to mobile view
</ng-container>
<ng-container #desktopview>
// all html related to desktop view
</ng-container>https://stackoverflow.com/questions/53919520
复制相似问题