我需要切换模板。我有12个css文件需要加载动态
我有一个模板html。它的工作,例如(硬码):
<div class="container">
<link rel='stylesheet' href="/app/switchTemplate/css/amelia/bootstrap.min.css" *ngIf="currentTheme.name === 'amelia'" />
</div>
当我使用<*ngFor="let theme of themes"> for标签"href"时它不工作(动态)
<div class="container">
<link rel='stylesheet' *ngFor="let theme of themes" href="{{theme.url}}" *ngIf="currentTheme.name === '{{theme.name}}'" />
</div>
我如何使用*ngFor在标签"href"中设置"URL",并在条件*ngIf中设置"{{theme.name}}"?
一个元素上不能有多个结构指令。您可以使用<template>
标记,但新的<ng-container>
元素更方便,因为它与普通元素上的结构指令使用相同的语法:
<div class="container">
<ng-container *ngFor="let theme of themes">
<link rel='stylesheet' href="{{theme.url}}" *ngIf="currentTheme.name === theme.name" />
</ng-container>
</div>
<template>
或<ng-container>
元素只在Angular2内部处理,不会添加到DOM中。