【发布时间】:2020-05-10 15:30:20
【问题描述】:
我需要在数组的第二个元素上设置 Style:"text-decoration: line-through",我该怎么做? 我尝试使用 CSS 和 [ngStyle] 但没有任何效果。 我的数组取自 HTTP 获取请求,但我认为它没有太大变化。 在我的 TypeScript 文件中,我有对象数组,但是如果我尝试在那里更改样式,则没有任何效果。
TypeScript:
export class TypeObjectComponent implements OnInit {
object: Objects[];
constructor(
private route: ActivatedRoute,
private router: Router,
private service: ObjectService
) { }
ngOnInit() {
this.service.getType().subscribe(data => {
this.object= data;
})
}
HTML:
<div class="form-group">
<label for="typeO" ><b>Type</b></label>
<select value="E" class="form-control" id="single" name="type">
<option [ngStyle]="{'text-decoration': line-through}" *ngFor="let Objects of object; index as i">
{{i}} - {{ Objects.type}}
</option>
</select>
</div>
【问题讨论】:
-
您的代码中没有使用
ngStyle。 -
尝试使用类添加更多类并为其编写 css 并仅更改类
标签: javascript html angular typescript http