Skip to content

Commit

Permalink
add remove components
Browse files Browse the repository at this point in the history
  • Loading branch information
Niclas Timle authored and Niclas Timle committed Sep 26, 2024
1 parent adb80b5 commit f302d40
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
6 changes: 0 additions & 6 deletions src/Components/BasicComponent/basic.component.css
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
.flex-fill{
border:5px solid white;
height: 300px;
width: 300px;
background-color: lightgray;
}
5 changes: 4 additions & 1 deletion src/Components/BasicComponent/basic.component.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<div class="d-flex text-center align-items-stretch bg-light" style="height: 300px;">
<div class="d-flex flex-wrap" style="height: 300px;">
<div *ngFor="let item of sharedService.flexItems" [innerHTML]="item"></div>

</div>


7 changes: 4 additions & 3 deletions src/Components/headerComponent/header.component.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<div class="d-flex flex-row-reverse">
<button (click)="onButtonClick()">...</button>
</div>
<div class="flex-wrap d-flex flex-row-reverse">
<button (click)="removeComponent()">Del</button>
<button (click)="addComponent()">Add</button>
</div>
5 changes: 4 additions & 1 deletion src/Components/headerComponent/header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export class HeaderComponent{

constructor(public sharedService: SharedService) {}

onButtonClick() {
addComponent() {
this.sharedService.addItem();
}
removeComponent() {
this.sharedService.removeItem();
}
}
2 changes: 1 addition & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component } from '@angular/core';
import { BasicComponent } from '../Components/BasicComponent/basic.component';
import { HeaderComponent } from "../Components/headerComponent/header.component";
import { HeaderComponent } from "../Components/HeaderComponent/header.component";

@Component({
selector: 'app-root',
Expand Down
15 changes: 11 additions & 4 deletions src/app/shared.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,21 @@ export class SharedService {
}

addItem() {
if(this.flexItems.length <= 4){
const newItem = this.sanitizeHtml(`<div
style="
height: 100%;
height: 300px;
width:330px;
margin-left:1.5em;
flex: 1 1 330px;
margin: 10px;
background:darkgrey;">Flex item ${this.flexItems.length}</div>`);
this.flexItems.push(newItem);
this.flexItems.push(newItem);
}
removeItem(){
if(this.flexItems.length > 1){
this.flexItems.splice(this.flexItems.length -1,1);
}
if(this.flexItems.length === 1){
this.flexItems.splice(this.flexItems.length,1);
}
}
}

0 comments on commit f302d40

Please sign in to comment.