Как я могу показать / скрыть div с помощью значков '+' или '-' fa? Я также хочу переключать значки, когда пользователь нажимает на них.
см. пример здесь:
Как мне это легко сделать?
Я голосую за то, чтобы закрыть этот вопрос как не по теме, потому что это не вопрос, потому что оригинальный плакат отвечает на него сразу после этого.





Есть очень простой способ сделать это очень просто. Я использую массив Boolean, чтобы получить этот результат
шаблон:
<div class = "box box-info" *ngFor = "let item of result; let x = index"> <!-- make loop for draw forms -->
<div class = "box-header with-border">
<h3 class = "box-title"><span *ngIf = "item.hasChildren" class = "fa fa-sign-out"></span> {{item.name}}</h3>
<div class = "box-tools pull-right">
<a class = "btn btn-box-tool" data-widget = "collapse" (click) = "toggle(x)">
<!-- use colapse[x] to change minus to plus -->
<i class = "fa" [ngClass] = "{'fa-minus': colapse[x], 'fa-plus': !colapse[x] }"></i>
</a>
</div>
</div>
<!-- show/hide div -->
<div class = "box-body" *ngIf = "colapse[x]">
<div class = "table-responsive">
<table class = "table no-margin">
<thead>
<tr>
<th>numbering</th>
<th>description</th>
<th>value</th>
</tr>
</thead>
<tbody>
<tr *ngFor = "let setting of item.configs; let i = index" >
<td>{{i + 1}}</td>
<td>{{setting.description}}</td>
<td class = "col-lg-3 col-md-4">
<input type = "text" class = "form-control" [(ngModel)] = "setting.value" name = "value" #ngvalue = "ngModel" value = "{{setting.description}}">
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
вот OnInit файла .ts:
export class MyComponent implements OnInit {
//for result from service
result: ConfigGroups[];
//for show/hide box
colapse: boolean[] = [false];
constructor(private settingService: SettingService) { }
ngOnInit() {
this.settingService.getConfigGroup(null, null).subscribe(res => {
//map return object to class
this.result = <ConfigGroups[]>res.data.configGroups;
}, error => { }, () => { });
}
// show/hide box and change fa icons
toggle(id) {
if (!this.colapse[id]) {
this.colapse[id] = true;
}
else {
this.colapse[id] = !this.colapse[id];
}
}
}
* ng Если можно решить проблему - и почему вы задаете вопрос, и отвечаете, я не понимаю