我有以下 html(为了说明而简化)。
//removed irrelevant HTML
<tbody>
<tr *ngFor="let el of elements; let i = index" >
<td>
<button (click)="showTemplate(i, $event)">Click me {{i}}</button>
</td>
</tr>
</tbody>
<template #myTemplate>
<tr>
<td>You have clicked a button</td>
</tr>
</template>
Run Code Online (Sandbox Code Playgroud)
我想要实现的是,当在特定中单击按钮时tr,应在该特定之后插入模板tr。
我认为我可以做的是使用 templateRef ViewChild,然后获取其节点并使用类似以下内容的内容:
@ViewChild('myTemplate', {read: TemplateRef}) myTemplate;
showTemplate(i, event) {
// i would get selectedTR from the event
selectedTR.insertAdjacentElement('afterend', this.myTemplate.elementRef.nativeElement)`
}
Run Code Online (Sandbox Code Playgroud)
this.myTemplate.elementRef.nativeElement但当函数运行时我得到的只是
我遵循的方法是正确的吗?如果是的话,那么我的设置可能有什么问题?如果没有,是否有更面向 Angular 的解决方案?
请注意我使用的是 Angular 2。
我可以在文档中看到语法是import { Observable } from 'rxjs';但import { Observable } from 'rxjs/internal/Observable有更好的吗?
我有以下代码:
return this.condition1
? condition2
? true
: false
: false
Run Code Online (Sandbox Code Playgroud)
有没有办法在不使用的情况下写这个true false?
a我有一个要为其设置颜色的元素。该规则在悬停时也应该起作用。我可以
a {
color: #color;
&:hover {
color: #color;
}
}
Run Code Online (Sandbox Code Playgroud)
它工作得很好,但我想知道是否有一种方法可以在不重复颜色规则的情况下做到这一点。