首页 > 解决方案 > 组件角度中加载 styleUrls 的条件

问题描述

我想在 styleUrls 中使用多 CSS

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: [condition 'if' for Which load css]
})

我累了

标签: angular

解决方案


您可以在内部使用三元运算符:

const url1 = './foo.css';
const url2 = './bar.css';

let condition = true

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: [condition ? url1 : url2]
})

推荐阅读