-
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.
added header button to add component
- Loading branch information
Niclas Timle
authored and
Niclas Timle
committed
Sep 25, 2024
1 parent
cbcd867
commit 1d3538f
Showing
10 changed files
with
86 additions
and
20 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,5 +1,6 @@ | ||
.flex-fill{ | ||
border:5px solid white; | ||
height: 300px; | ||
width: 300px; | ||
background-color: lightgray; | ||
} |
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,10 +1,3 @@ | ||
<div class="d-flex text-center"> | ||
<div class="p-2 flex-fill">Flex item 1</div> | ||
<div class="p-2 flex-fill">Flex item 2</div> | ||
<div class="p-2 flex-fill">Flex item 3</div> | ||
</div> | ||
<div class="d-flex text-center"> | ||
<div class="p-2 flex-fill">Flex item 1</div> | ||
<div class="p-2 flex-fill">Flex item 2</div> | ||
<div class="p-2 flex-fill">Flex item 3</div> | ||
<div class="d-flex text-center align-items-stretch bg-light" 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 |
---|---|---|
@@ -1,11 +1,14 @@ | ||
import { Component } from '@angular/core'; | ||
import { Component, ViewEncapsulation } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; // Import CommonModule for *ngFor | ||
import { SharedService } from '../../app/shared.service'; | ||
|
||
@Component({ | ||
selector: 'basic-component', | ||
standalone: true, | ||
templateUrl: './basic.component.html', | ||
styleUrl: './basic.component.css', | ||
}) | ||
export class BasicComponent{ | ||
|
||
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,3 @@ | ||
<div class="d-flex flex-row-reverse"> | ||
<button (click)="onButtonClick()">...</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,18 @@ | ||
import { Component } from "@angular/core"; | ||
import { SharedService } from '../../app/shared.service'; | ||
|
||
@Component({ | ||
selector: 'header-component', | ||
standalone: true, | ||
templateUrl: './header.component.html', | ||
styleUrl: './header.component.css', | ||
}) | ||
|
||
export class HeaderComponent{ | ||
|
||
constructor(public sharedService: SharedService) {} | ||
|
||
onButtonClick() { | ||
this.sharedService.addItem(); | ||
} | ||
} |
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
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,32 @@ | ||
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() { | ||
if(this.flexItems.length <= 4){ | ||
const newItem = this.sanitizeHtml(`<div | ||
style=" | ||
height: 100%; | ||
width:330px; | ||
margin-left:1.5em; | ||
background:darkgrey;">Flex item ${this.flexItems.length}</div>`); | ||
this.flexItems.push(newItem); | ||
} | ||
} | ||
} |
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; | ||
} |