How to change button position in angular? - html

I want to change the button position in my html code but I got a problem in the j like in the photo below ! I want to put the button in the footer of the modal !
the Output (button in the bottom) :
here is it my code:
<div class="modal-header" >
<h6 class="modal-title" id="modal-basic-title">Notes</h6>
<button type="button" class="close" aria-label="Close" (click)="closemodal()">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body" style="width:500px ; height:600px; overflow-y: auto" >
<mat-accordion >
<mat-expansion-panel *ngFor="let i of listCategorie" class="parentPanel" >
<mat-expansion-panel-header class="parentPanel_header" (click)="getSouCategories(i.id)" >
<mat-panel-title > {{i.libelle}} {{i.id}}
<span class="badge badge-light " style="position:absolute; right:6em"> {{listCategorie.length}} </span>
</mat-panel-title>
</mat-expansion-panel-header>
<mat-accordion multi>
<mat-expansion-panel style="background-color: #EEDFF5;" class="childPanel childPanelCount" [expanded]="true" hideToggle disabled>
<div class="d-flex mt-2">
<div class="p-2"><p> Nombre des sous catégories </p></div>
<div class="ml-auto p-2">
<span class="badge badge-secondary "> {{listSousCategorie.length}} </span>
</div>
</div>
</mat-expansion-panel>
<ng-container>
<mat-expansion-panel class="childPanel" [expanded]="true" hideToggle disabled style=" background:#F2EDFF;"
*ngFor="let j of listSousCategorie; ">
<div class="childPanel_body2 mat-badge-large" fxLayout="row" fxFlex fxLayoutAlign="start center">
<div style="padding-left:1em" fxFlex="grow">{{j.libelle}} {{j.id}}</div>
<mat-form-field style="width:50px" appearance="standard">
<form>
<mat-label>Note</mat-label>
<input type="text" matInput name="Note" [(ngModel)]="j.Note_Condidat">
<button type="button" (click)="onSubmit(j)"> ok</button>
</form>
</mat-form-field>
</div>
</mat-expansion-panel>
</ng-container>
</mat-accordion>
</mat-expansion-panel>
</mat-accordion>
</div>
Ts File:
onSubmit(sous) {
this.LExamenSousCategorieService.updateSouCategorie(sous).then(res => {
})
}

i think you should give parent element of button "position: relative" and make your button positioning with "position: absolute; (and margin,padding vs...)"

Related

dynamically add or remove buttons alignment in form

I have a small form designed but it is misaligned. I am trying to align properly but not sure why its becoming so messy. The problem with the design is when i click on plus button the below things happen:
The blue color content right side gets increased and in turn it adds extra space vertically which is messy. I want the blue color content to be at fixed height.
The minus button needs to be placed properly beside its corresponding line.
Also the plus button should be aligned properly.
Can anyone help me out on this.
The below is my code:
<div class="row">
<div class="col-md-8">
<mat-dialog-content class="mat-typography">
<section *ngFor="let address of endpointsBulk; let i = index;">
<div class="row">
<div>
<!-- <h4>Endpoint {{i + 1}}</h4> -->
</div>
<div class="text-right" *ngIf="endpointsBulk.length > minEndpoints">
<button mat-button color="danger" (click)="removeEndpointForm(i)">
<i class="fa fa-minus" aria-hidden="true"></i>
</button>
</div>
</div>
<div class="row">
<div>
<mat-form-field class="example-full-width">
<mat-label>Choose Method</mat-label>
<mat-select [(ngModel)]="address.method">
<mat-option value="post">POST</mat-option>
<mat-option value="get">GET</mat-option>
<mat-option value="put">PUT</mat-option>
<mat-option value="delete">DELETE</mat-option>
</mat-select>
</mat-form-field>
</div>
<div>
<mat-form-field class="example-full-width">
<input name="search" id="search" [(ngModel)]="address.endpoint" matInput type="search"
placeholder="Endpoint">
</mat-form-field>
</div>
</div>
</section>
<div class="text-right" *ngIf="endpointsBulk.length < maxEndpoints">
<button mat-button color="primary" (click)="addEndpoinForm();">
<i class="fa fa-plus" aria-hidden="true"></i>
</button>
</div>
</mat-dialog-content>
</div>
<div class="col-md-4 callout callout-info no-margin">
<li>Format: post:/api/v1/addAccount/id
<br> Usage :
<ul>
<li>post:/api/v1/addAccount/id</li>
<li>get:/api/v1/getAccount/id</li>
<li>put:/api/v1/updateAccount/id</li>
<li>delete:/api/v1/deleteAccount/id</li>
</ul>
</li>
</div>
</div>
<mat-dialog-actions class="pull-right" align='end'>
<button mat-raised-button class="nav-btn text-primary" type="submit" [disabled]="checkFormValidity()"
(click)="saveEndPoint()">Save</button>
<button mat-raised-button class="nav-btn text-primary" (click)="dialogRef.close()">Cancel</button>
</mat-dialog-actions>
The design is something like below:
You can limit the height of the right side with height: fit-content;
You seem to be putting each element (minus, form) inside a separate row, try using columns instead if you want them next to each other
The alignment of plus is just a matter of putting it in a correct container, please specify what is "aligned properly"

The data is not rendering in the mat-menu

I been trying to create a navbar with a submenu. The nav bar data is rendered successfully but the submenu is not working, I am very new to this. Please let me know where is the problem.
<mat-nav-list class="navigation relative">
<div *ngFor="let link of navLinks; let i=index" style="padding-bottom: 14px;">
<div class="card">
<mat-list-item appAccordionlinks routerLinkActive="active-link" (click)="onClick(link.name)">
<a mat-button [matMenuTriggerFor]="submenu" *ngIf="link?.submenu?.length > 0" appAccordiontoggle
class="relative main-active">
<mat-icon *ngIf="link.icon">{{link.icon}}</mat-icon>
<img class="menu-img" *ngIf="link.img" [src]="link.img" alt="">
<app-menu-icon *ngIf="link.img" [name]="'employee'"></app-menu-icon>
<span>{{link.name}}</span><span fxFlex></span>
</a>
<a *ngIf="!(link?.submenu?.length > 0)" [routerLink]="link.path" appAccordiontoggle
class="relative main-active" mat-ripple fxLayout="row">
<mat-icon *ngIf="link.icon">{{link.icon}}</mat-icon>
<app-menu-icon *ngIf="link.img" [name]="link.name" [color]="link.color"></app-menu-icon>
<!-- <img class="menu-img" *ngIf="link.img" [src]="link.img" alt=""> this is need to mark as comment -->
<span>{{link.name}}</span>
</a>
</mat-list-item>
</div>
</div>
</mat-nav-list>
<mat-menu #submenu>
<ng-container *ngFor="let sublink of link?.submenu">
<ng-container *ngIf="link?.submenu?.length > 0">
<button mat-menu-item>
<img class="menu-img" *ngIf="sublink.img" [src]="sublink.img">
<span>{{sublink.name}}</span>
</button>
</ng-container>
</ng-container>
</mat-menu>
The mat-menu element is out of the scope of link variable. You need to include it (mat-menu) in the div you are dynamically rendering the links, i.e. within link's scope:
<div *ngFor="let link of navLinks; let i = index"...>
<--! card html -->
<mat-menu #submenu>
<--! submenu child elements... -->
</mat-menu>
</div>

How to show only two button in single row

I am using *ngFor for displaying multiple buttons, it can have many buttons. Currently I am getting all the buttons in one column, means one below one.
But I want to display only 2 buttons in a row, means, in above case these green buttons should be in one line, and 2 red buttons should be in next line just below of it. How can I do this?
This is I tried:
<div class="row mt-3">
<div class="col-sm-5"></div>
<div class="col-sm-7">
<div *ngFor="let actionButton of actionButtonData">
<div *ngIf="actionButton.Direction === 1">
<button type="button" class="btn actionButton btn-success">
{{ actionButton.Name }}
</button>
</div>
<div *ngIf="actionButton.Direction === 2">
<button type="button" class="btn actionButton btn-danger">
{{ actionButton.Name }}
</button>
</div>
</div>
</div>
</div>
css
.actionButton {
width: 200px;
display: inline-block;
overflow: hidden !important;
white-space: nowrap;
text-overflow: ellipsis
}
<div class='row'>
<div class='col'>
<div class='row'>
<button >
button1
</button>
<button >
button2
</button>
</div>
<div class='row'>
<button >
button1
</button>
<button >
button2
</button>
</div>
</div>
</div>
try this row col method
you could group buttons in bootstrap. for your purpose, add btn-group class to ngIf div. it's bootstrap feature and you don't need any custom css.
<div class="row mt-3">
<div class="col-sm-5"></div>
<div class="col-sm-7">
<div *ngFor="let actionButton of actionButtonData">
<div *ngIf="actionButton.Direction === 1" class="btn-group">
<button type="button" class="btn actionButton btn-success">
{{ actionButton.Name }}
</button>
</div>
<div *ngIf="actionButton.Direction === 2" class="btn-group">
<button type="button" class="btn actionButton btn-danger">
{{ actionButton.Name }}
</button>
</div>
</div>
</div>
</div>
You could make it by using normal bootstrap, add class row to parent div and add class col-sm-6 to every child will make only 2 children in that row
<div *ngFor="let actionButton of actionButtonData" class="row"> <!--here-->
<div *ngIf="actionButton.Direction === 1" class="col-sm-6"> <!--here-->
<button type="button" class="btn actionButton btn-success">
{{ actionButton.Name }}
</button>
</div>
<div *ngIf="actionButton.Direction === 2" class="col-sm-6"> <!--here-->
<button type="button" class="btn actionButton btn-danger">
{{ actionButton.Name }}
</button>
</div>
</div>

Sidenav angular materials trying to be side to side with other component

The Problem: In an angular project I have a single component for the sidenav menu and I'm trying to put other component sided with the sidenav, but since the sidenav element has full height the other component just goes to the bottom of the page. I tried to use display flex, but still goes to the bottom of the page.
Sidenav - html
<mat-drawer-container class="container" autosize>
<mat-drawer #drawer class="p-5" mode="side">
<!-- Content for side menu -->
<!-- Title -->
<h2 class="mt-5">Menu</h2>
<!-- Menu options-->
<button mat-button class="m-2" [matMenuTriggerFor]="workexperience">Experiência
Profissional</button>
<button mat-button class="m-2" [matMenuTriggerFor]="studies">Educação</button>
<button mat-button class="m-2" [matMenuTriggerFor]="skills">Habilidades</button>
<...>
<!-- Option work experience-->
<mat-menu #workexperience="matMenu">
<button mat-menu-item>text</button>
<button mat-menu-item>text</button>
</mat-menu>
<...>
</mat-drawer>
</mat-drawer-container>
<nav class="navbar navbar-light cyan darken-3 text-white fixed-top">
<button type="button" mat-button (click)="drawer.toggle()">
<mat-icon class="mx-2">menu</mat-icon>
<p class="mr-4 d-inline">Menu</p>
</button>
<button type="button" routerLink="/home" routerLinkActive="active" mat-raised-button>
<mat-icon class="d-inline mx-2" aria-label="Example home icon">home</mat-icon>
<p class="mr-4 d-inline">Home</p>
</button>
<a class="navbar-brand d-inline mx-5" routerLink="/bio">
<img class="rounded-circle z-depth-2" alt="80x80" height="35" src="https://mdbootstrap.com/img/Photos/Avatars/img%20(31).jpg"
data-holder-rendered="true">
<p class="d-inline mx-3 text-white">text</p>
</a>
</nav>
Sidenav- css
.container {
display: inline-block;
height: 100%;
background-color: white;
}
The other component that I want to be on the rigth of the navside.
The other component html
<mat-grid-list cols="4" rowHeight="500" class="m-5 sidenav-content">
<mat-grid-tile
*ngFor="let tile of tiles"
[colspan]="tile.cols"
[rowspan]="tile.rows"
[style.background]="tile.color">
{{tile.text}}
</mat-grid-tile>
</mat-grid-list>
The other component css
.sidenav-content{
display: flex;
height: 100%;
}

I want add two two div's in a single div

I want add two div's in a single div one is to right and other is to left.
<html>
<div>
<div><button class="mat-button menu-button">
<mat-icon color="primary"> remove </mat-icon>
Add Site
</button>
</div>
<div *ngIf="showButtons">
<button>edit</button>
<button >Save</button>
</div>
</div>
</html>
use float css property to align div left and right
.left {
float: left;
}
.right {
float: right;
}
<div>
<div class='left'><button class="mat-button menu-button">
<mat-icon color="primary"> remove </mat-icon>
Add Site
</button>
</div>
<div *ngIf="showButtons" class='right'>
<button>edit</button>
<button>Save</button>
</div>
</div>
you can use ng-container instead of div for button one is to right and other is to left.
<div>
<button class="mat-button menu-button">
<mat-icon color="primary"> remove </mat-icon>
Add Site
</button>
<ng-container *ngIf="showButtons">
<button>edit</button>
<button>Save</button>
</ng-container>
</div>
You could set the display to flex, the default direction is row :
<div style="display:flex;">
<div><button class="mat-button menu-button">
<mat-icon color="primary"> remove </mat-icon>
Add Site
</button>
</div>
<div *ngIf="showButtons">
<button>edit</button>
<button >Save</button>
</div>
</div>
.firstCol{
float : left;
}
<html>
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="firstCol"><button class="mat-button menu-button">
<mat-icon color="primary"> remove </mat-icon>
Add Site
</button>
</div>
<div *ngIf="showButtons">
<button>edit</button>
<button >Save</button>
</div>
</div>
</div>
</div>
</html>
You did it well, just add a class name or an Id on the div and you can do what you want with CSS with for exemple the float property.