-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Niclas Timle
authored and
Niclas Timle
committed
Nov 8, 2024
1 parent
6ded524
commit 4513ccb
Showing
5 changed files
with
30 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
<div class="d-flex flex-wrap" style="height: 300px;"> | ||
<div *ngFor="let item of sharedService.flexItems" [innerHTML]="item"></div> | ||
<div *ngFor="let item of sharedService.flexItems" | ||
class="action-btn" | ||
style="height: 300px; width:330px; flex: 1 1 330px; margin: 10px; background:darkgrey;"> | ||
Flex item | ||
<button (click)="Remove(item.id)">Remove Button </button> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,31 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { DomSanitizer, SafeHtml } from '@angular/platform-browser'; // Import DomSanitizer and SafeHtml | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
|
||
export class SharedService { | ||
public flexItems: SafeHtml[] = []; | ||
flexItems: { id: number }[] = []; | ||
|
||
constructor(private sanitizer: DomSanitizer){ | ||
this.flexItems = [ | ||
this.sanitizeHtml('') | ||
]; | ||
Remove(id: number) { | ||
let index = this.GetId(id); | ||
if(index > -1){ | ||
this.flexItems.splice(index, 1); | ||
} | ||
} | ||
|
||
sanitizeHtml(html: string): SafeHtml { | ||
return this.sanitizer.bypassSecurityTrustHtml(html); | ||
AddItem() { | ||
const newId = Math.floor(Math.random() * 100) + 1; | ||
let index = this.GetId(newId); | ||
console.log(index); | ||
if(index === -1){ | ||
this.flexItems.push({ id: newId }); | ||
} | ||
else | ||
this.AddItem(); | ||
} | ||
|
||
addItem() { | ||
const newItem = this.sanitizeHtml(`<div | ||
style=" | ||
height: 300px; | ||
width:330px; | ||
flex: 1 1 330px; | ||
margin: 10px; | ||
background:darkgrey;">Flex item ${this.flexItems.length}</div>`); | ||
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); | ||
} | ||
GetId(id: number): number{ | ||
return this.flexItems.findIndex(item => item.id == id); | ||
} | ||
} |