-
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.
Merge pull request #20 from Carpenteri1/1-add--remove-components
1 add remove components
- Loading branch information
Showing
13 changed files
with
100 additions
and
29 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,4 @@ | ||
<header-component></header-component> | ||
<div class="container-fluid p-2"> | ||
<basic-component></basic-component> | ||
</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
Empty file.
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="d-flex flex-wrap" style="height: 300px;"> | ||
<div *ngFor="let item of sharedService.flexItems" [innerHTML]="item"></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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Component } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; // Import CommonModule for *ngFor | ||
import { SharedService } from '../../shared.service'; | ||
|
||
@Component({ | ||
selector: 'basic-component', | ||
standalone: true, | ||
imports: [CommonModule], | ||
templateUrl: './basic.component.html', | ||
styleUrls: ['./basic.component.css'], | ||
}) | ||
export class BasicComponent { | ||
constructor(public sharedService: SharedService) {} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.d-flex{ | ||
background-color: antiquewhite; | ||
} | ||
.flex-row-reverse{ | ||
padding-right: 1em; | ||
padding-top: 0.5em; | ||
padding-bottom: 0.5em; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div class="flex-wrap d-flex flex-row-reverse"> | ||
<button (click)="removeComponent()">Del</button> | ||
<button (click)="addComponent()">Add</button> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Component } from "@angular/core"; | ||
import { SharedService } from '../../shared.service'; | ||
|
||
@Component({ | ||
selector: 'header-component', | ||
standalone: true, | ||
templateUrl: './header.component.html', | ||
styleUrl: './header.component.css', | ||
}) | ||
|
||
export class HeaderComponent{ | ||
|
||
constructor(public sharedService: SharedService) {} | ||
|
||
addComponent() { | ||
this.sharedService.addItem(); | ||
} | ||
removeComponent() { | ||
this.sharedService.removeItem(); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
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[] = []; | ||
|
||
constructor(private sanitizer: DomSanitizer){ | ||
this.flexItems = [ | ||
this.sanitizeHtml('') | ||
]; | ||
} | ||
|
||
sanitizeHtml(html: string): SafeHtml { | ||
return this.sanitizer.bypassSecurityTrustHtml(html); | ||
} | ||
|
||
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); | ||
} | ||
} | ||
} |
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,9 @@ | ||
/* You can add global styles to this file, and also import other style files */ | ||
@import "bootstrap/dist/css/bootstrap.css"; | ||
@import "bootstrap-icons/font/bootstrap-icons.css"; | ||
@import "bootstrap-icons/font/bootstrap-icons.css"; | ||
.flex-fill{ | ||
border:5px solid white; | ||
height: 300px; | ||
width: 300px; | ||
background-color: lightgray; | ||
} |