Skip to content

Commit

Permalink
Merge pull request #20 from Carpenteri1/1-add--remove-components
Browse files Browse the repository at this point in the history
1 add  remove components
  • Loading branch information
Carpenteri1 authored Sep 26, 2024
2 parents cbcd867 + 065373e commit bf8a3ab
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 29 deletions.
5 changes: 0 additions & 5 deletions src/Components/BasicComponent/basic.component.css

This file was deleted.

10 changes: 0 additions & 10 deletions src/Components/BasicComponent/basic.component.html

This file was deleted.

11 changes: 0 additions & 11 deletions src/Components/BasicComponent/basic.component.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/app/app.component.html
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>
5 changes: 3 additions & 2 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Component } from '@angular/core';
import { BasicComponent } from '../Components/BasicComponent/basic.component';
import { BasicComponent } from '../app/components/basicComponent/basic.component';
import { HeaderComponent } from "../app/components/header/header.component";

@Component({
selector: 'app-root',
standalone: true,
templateUrl: './app.component.html',
styleUrl: './app.component.css',
imports: [BasicComponent],
imports: [BasicComponent, HeaderComponent],
})
export class AppComponent {
title = 'Gridly';
Expand Down
Empty file.
3 changes: 3 additions & 0 deletions src/app/components/basicComponent/basic.component.html
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>
14 changes: 14 additions & 0 deletions src/app/components/basicComponent/basic.component.ts
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) {}
}
8 changes: 8 additions & 0 deletions src/app/components/header/header.component.css
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;
}
4 changes: 4 additions & 0 deletions src/app/components/header/header.component.html
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>
21 changes: 21 additions & 0 deletions src/app/components/header/header.component.ts
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();
}
}
39 changes: 39 additions & 0 deletions src/app/shared.service.ts
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);
}
}
}
8 changes: 7 additions & 1 deletion src/styles.css
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;
}

0 comments on commit bf8a3ab

Please sign in to comment.