Hello all I have the following piece of code:
<table class="details-table" *ngIf="peop && peopMetadata">
<tr *ngFor="let attribute of peopMetadata.Attributes">
<td class="details-property">{{attribute.AttributeLabel}}</td>
<td [ngSwitch]="attribute.AttributeType">
<div *ngSwitchCase="'String'">
<input matInput [(ngModel)] = "peop[attribute.AttributeKey]" />
</div>
<div *ngSwitchDefault>{{peop[attribute.AttributeKey]}
</div>
</td>
</tr>
<div>
<button ng-click="">Submit</button>
</div>
</table>
I want to disable the input based on an attribute values say peop[attribute.IsWritable]='false' . How can i achieve this here . Any help is appreciated
INPUT only approach:
<input [disabled]="!peop[attribute.IsWritable]" matInput [(ngModel)] = "peop[attribute.AttributeKey]" />
CONDITIONAL approach:
<ng-container *ngIf="peop[attribute.IsWritable]">
<input matInput [(ngModel)]="peop[attribute.AttributeKey]" />
</ng-container>
<ng-container *ngIf="!peop[attribute.IsWritable]">
<span>{{ peop[attribute.AttributeKey] }}</span>
</ng-container>
OR:
<input *ngIf="peop[attribute.IsWritable]" matInput [(ngModel)]="peop[attribute.AttributeKey]" />
<span *ngIf="!peop[attribute.IsWritable]">{{ peop[attribute.AttributeKey] }}</span>
I just came across the need to do this and found that I needed to use ng-disabled to do it.
<input id="my-input-id" class="my-input-class" type="number" name="my-input-name" ng-model="MyCtrl.myModel" required ng-disabled="MyCtrl.myProperty && MyCtrl.myProperty !== 'someValue'"></input>
Hope this helps someone else!
Related
I can't write in input inside the expansion-panel, the focus is removed once I click on the input.
here is it my code!
<ng-container *ngFor="let i of listSousCategorie">
<mat-expansion-panel class="childPanel" [expanded]="true" hideToggle disabled style=" background:#ecfaff;">
<div class="childPanel_body2 mat-badge-large" fxLayout="row" fxFlex fxLayoutAlign="start center" >
<div style="padding-left:1em" fxFlex="grow" >{{i.libelle}}</div>
<mat-form-field style="width:50px" appearance="standard" [formGroup]="form">
<mat-label>Note</mat-label>
<input type="text" matInput formControlName="Note" " >
</mat-form-field>
</div>
</mat-expansion-panel>
</ng-container>
<div class="carousel-cell lw-pr-30" style="width: 220px;" *ngFor="let item of product?.products; let i = index">
<div class="lw-w-auto lw-h-80p">
<div class="lw-ff-Ubuntu lw-fs-18"> $ {{item.price}}</div>
<div class="lw-fs-12 lw-ff-Ubuntu">{{item.name}}</div>
<div class="lw-fs-12 lw-ff-Ubuntu">1 Lbs</div>
</div>
<mat-icon class="lw-ta-e " style="float: right;height: 40px;" *ngIf="!item.cart" (click)="addCart(names,item)" svgIcon="cartround"></mat-icon>
<div class="lw-ta-e lw-d-flex lw-align-center" style="float: right;height: 40px;" *ngIf="item.cart">
<mat-icon (click)="removeCounter(names,item)" svgIcon="minus" class="lw-cursor-p"></mat-icon>
<input type="text" class="count" [ngModelOptions]="{standalone: true}" [(ngModel)]="names" name = 'names' min="1" maxlength="2" max="20" disabled/>
<!-- ngModel #names="ngModel" -->
<mat-icon (click)="addCounter(names,item)" svgIcon="plus" class="lw-cursor-p"></mat-icon>
</div>
</div>
</div>
sample image
when i click on plus button all the input changes at a time.how to change the clicked button's input
I think there is a typo.
try to change
(click)="..(*names*,item)"
to
(click)="..(*name*,item)"
if not try to use index
if possible please share stackblitz we can help.
What i am trying to do here is display input boxes for each of the people using ngFor. However this only lets me make selection from the first input box and when i make the selection it automatically updates the remaining inputs with the same value. Can anyone help me understand what i could be doing wrong here and i would like to be able to update the values for each person from the people array individually
<table>
<tr>
<td class="detailS">Hours</td>
<td style="width: auto" nowrap class="opt">
<mat-list>
<mat-list-item class="item"
*ngFor="let member of people.value; let i = index">
<div style="margin-left: 50px" nowrap>Start</div>
<div style="margin-left: 30px" *ngIf="edit">
<mat-form-field>
<input matInput [matAutocomplete]="startAuto"
formControlName="start" (click)="onChooseStart()"
required="true">
<mat-autocomplete #startAuto="matAutocomplete"
(optionSelected)="onStartSelected($event)">
<mat-option *ngFor="let time of filteredStart | async"
[value]="time">
{{time | amDateFormat:'h:mm a'}}
</mat-option>
</mat-autocomplete>
</mat-form-field>
</div>
<div style="margin-left: 50px" *ngIf="!edit">
{{start?.value}}
</div>
<div style="margin-left: 50px" nowrap>End</div>
<div style="margin-left: 30px" *ngIf="edit">
<mat-form-field>
<input style="width: 70px" #endInput matInput
[matAutocomplete]="endAuto" (click)="onChooseEnd()"
formControlName="end" required="true">
<mat-autocomplete #endAuto="matAutocomplete"
(optionSelected)="onEndSelected($event)">
<mat-option *ngFor="let time of filteredEnd | async"
[value]="time">
{{time | amDateFormat:'h:mm a'}}{{getDifference(formGroup.get('start').value, time)}}
</mat-option>
</mat-autocomplete>
</mat-form-field>
</div>
<div style="margin-left: 50px" *ngIf="!edit">
{{end?.value}}
</div>
</mat-list-item>
</mat-list>
</tr>
</table>
I am using Angular Material to design a basic form, but I am stuck with trying to create the functionality to add a dynamic row to the form. I.e., when I click an "add" button next to a row, it should add a new empty row.
I have tried numerous ways to make use of this example, but my data either repeats, or my list bombs out:
The form code:
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Code</th>
<th>Name</th>
<th>Price</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let field of fieldArray; let i = index">
<td>
<input [(ngModel)]="field.code" class="form-control" type="text" name="{{field.code}}" />
</td>
<td>
<input [(ngModel)]="field.name" class="form-control" type="text" name="{{field.name}}" />
</td>
<td>
<input [(ngModel)]="field.price" class="form-control" type="text" name="{{field.price}}" />
</td>
<td>
<button mat-raised-button class="form-button-spacing" color="warn" type="button" (click)="deleteFieldValue(i)">
Delete</button>
</td>
</tr>
<tr>
<td>
<input class="form-control" type="text" id="newAttributeCode" [(ngModel)]="newAttribute.code" name="newAttributeCode" />
</td>
<td>
<input class="form-control" type="text" id="newAttributeName" [(ngModel)]="newAttribute.name" name="newAttributeName" />
</td>
<td>
<input class="form-control" type="text" id="newAttributePrice" [(ngModel)]="newAttribute.price" name="newAttributePrice"
/>
</td>
<td>
<button mat-raised-button class="form-button-spacing" color="primary" type="button" (click)="addFieldValue()">
Add</button>
</td>
</tr>
</tbody>
</table>
The component code:
private fieldArray: Array<any> = [];
private newAttribute: any = {};
addFieldValue() {
this.fieldArray.push(this.newAttribute)
this.newAttribute = {};
}
deleteFieldValue(index) {
this.fieldArray.splice(index, 1);
}
How can I use my code below to create the same dynamically added rows:
<mat-expansion-panel [expanded]="step === 4" (opened)="setStep(4)" hideToggle="true">
<mat-expansion-panel-header>
<mat-panel-title>
<h4>Permits</h4>
</mat-panel-title>
<mat-panel-description>
<div></div>
<mat-icon>whatshot</mat-icon>
</mat-panel-description>
</mat-expansion-panel-header>
<div class="form">
<form class="permits-form" #permitsForm="ngForm" (ngSubmit)=onSubmit(permitsForm)>
<input type="hidden" name="AssetID" #AssetID="ngModel" [(ngModel)]="assetDataService.selectedAsset.AssetID">
<table class="full-width" cellspacing="0">
<tr>
<td>
<mat-form-field>
<mat-select placeholder="Permits" id="Permits" name="Permits" #Permits="ngModel" [(ngModel)]="assetDataService.selectedAsset.Permits"
required>
<mat-option *ngFor="let permit of permits" [value]="permit.name" required>
{{ permit.name }}
</mat-option>
</mat-select>
</mat-form-field>
</td>
<td>
<mat-form-field class="full-width">
<input matInput placeholder="Title of Permit" id="PermitTitle" name="PermitTitle" #PermitTitle="ngModel" [(ngModel)]="assetDataService.selectedAsset.PermitTitle"
required>
</mat-form-field>
</td>
<td>
<mat-form-field class="full-width">
<input matInput [matDatepicker]="PermitIssueDate" placeholder="Issue Date" id="PermitIssueDate" name="PermitIssueDate" #PermitIssueDate="ngModel"
[(ngModel)]="assetDataService.selectedAsset.PermitIssueDate" required>
<mat-datepicker-toggle matSuffix [for]="PermitIssueDate"></mat-datepicker-toggle>
<mat-datepicker touchUi="true" #PermitIssueDate></mat-datepicker>
</mat-form-field>
</td>
<td>
<mat-form-field class="full-width">
<input matInput [matDatepicker]="PermitEndDate" placeholder="Expiry Date" id="PermitEndDate" name="PermitEndDate" #PermitEndDate="ngModel"
[(ngModel)]="assetDataService.selectedAsset.PermitEndDate">
<mat-datepicker-toggle matSuffix [for]="PermitEndDate"></mat-datepicker-toggle>
<mat-datepicker touchUi="true" #PermitEndDate></mat-datepicker>
</mat-form-field>
</td>
<td>
<mat-icon>add_circle_outline</mat-icon>
</td>
</tr>
</table>
</form>
</div>
</mat-expansion-panel>
Thank you in advance!
You should use reactive forms and you can add form controls dynamically.
I was able to resolve my need by implementing the following:
First, in my view I created another mat-table to hold and loop my added lines, as well as fetch the data source and assigning it to the table:
<mat-table #table [dataSource]="getPermitDataSource()">
<!-- Id Column -->
<ng-container matColumnDef="permit">
<mat-header-cell *matHeaderCellDef> Permit </mat-header-cell>
<mat-cell *matCellDef="let permit"> {{permit.Permits}} </mat-cell>
</ng-container>
<!-- Make Column -->
<ng-container matColumnDef="title">
<mat-header-cell *matHeaderCellDef> Permet Title </mat-header-cell>
<mat-cell *matCellDef="let permit"> {{permit.PermitTitle}} </mat-cell>
</ng-container>
<!-- Model Column -->
<ng-container matColumnDef="issue">
<mat-header-cell *matHeaderCellDef> Issue Date </mat-header-cell>
<mat-cell *matCellDef="let permit"> {{permit.PermitIssueDate | date}} </mat-cell>
</ng-container>
<!-- Regitration Column -->
<ng-container matColumnDef="expiry">
<mat-header-cell *matHeaderCellDef> Expiry Date </mat-header-cell>
<mat-cell *matCellDef="let permit"> {{permit.PermitEndDate | date}} </mat-cell>
</ng-container>
<!-- actions -->
<ng-container matColumnDef="actions">
<mat-header-cell *matHeaderCellDef>Edit | Delete</mat-header-cell>
<mat-action-row>
<mat-cell *matCellDef="let permit; let i=index;">
<button mat-icon-button class="form-button-spacing float-right" color="primary" (click)="onPermitDelete(permitsForm)">
<mat-icon aria-label="Delete">delete</mat-icon>
</button>
</mat-cell>
</mat-action-row>
</ng-container>
<!-- <mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row> -->
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
</mat-table>
Secondly, I implemented the functionality in my component:
addNewPermitToArray(form: NgForm) {
this.permitArray.push(form.value);
this.getPermitDataSource();
form.reset();
}
getPermitDataSource() {
this.displayedColumns = this.displayedColumns = ['permit', 'title', 'issue', 'expiry', 'actions'];
return this.permitDataSource = new MatTableDataSource(this.permitArray);
}
I hope this will help someone else out there!
I am making 2 different web application for smart phones, using jQuery mobile and webapp-net.
so far I have the following codes: (its just a part of these codes, since I can not put the whole thing here)
<div data-role="collapsible" data-collapsed="true">
<h3>Eenmalige machtiging </h3>
<div data-role="fieldcontain" >
<form >
<input type="number" pattern="[0-9]*" id="anum" maxlength="9" placeholder="Account Number" autocomplete="off" onBlur="isValidAnum()" onFocus="emptyAnum('anum')"/>
<input type="text" id="bname" placeholder="Beneficiary Name" autocomplete="off" onBlur="isValidBname()" onFocus="emptyBname('bname')"/>
<table>
<tr><td>
Select Your Bank
</td>
<td>
<select name="select-bank" id="select-bank" class="select-bank" data-inline = "true" >
<option value="abn">ABN Amro</option>
<option value="rabo">Rabo Bank</option>
<option value="ing">ING Bank</option>
<option value="overige"> --Overig--</option>
</select>
</td>
</tr>
</table>
<table>
<tr>
<td>I Agree </td>
<td><input type="checkbox" class = "checkbox" name="cbox" id="cbox2"/></td>
</tr>
<tr>
<td> </td>
</tr>
</table>
<br/>
<a data-role = "button" type="submit" data-icon = "check" data-theme="b">Pay</a>
</form>
</div>
</div>
</div>
</div>
and:
<button class="form_header" id="last_method"><img src="appimages/directdebit_NL.png" align="middle" /> Eenmalige Machtiging</button>
<div class="form_body">
<fieldset>
<ul>
<li>
<input type="number" pattern="[0-9]*" id="anum" maxlength="9" placeholder="Account Number" autocomplete="off" onBlur="isValidAnum()" onFocus="emptyAnum('anum')"/>
</li>
<li>
<input type="text" id="bname" placeholder="Beneficiary Name" autocomplete="off" onBlur="isValidBname()" onFocus="emptyBname('bname')"/>
</li>
<li>
<table>
<tr><td>
Select Your Bank
</td>
<td>
<select name="select-bank" id="select-bank" class="select-bank" data-inline = "true" >
<option value="abn">ABN Amro</option>
<option value="rabo">Rabo Bank</option>
<option value="ing">ING Bank</option>
<option value="overige"> --Overig--</option>
</select>
</td>
</tr>
</table>
</li>
<li>
<table>
<tr>
<td>I Agree </td>
<td><input type="checkbox" class = "checkbox" name="cbox" id="cbox2" /></td>
</tr>
<tr>
<td> </td>
</tr>
</table>
<input type="submit" value="Pay" class="pay_button"/>
</li>
</ul>
</fieldset>
</div>
</div>
</div>
Now I have to create a .vm file using these two codes, in order to do that I need to see what are the difference in html between these two. I tried to make it look alike each other as much as I could, I dont think I can change them any more. I was also trying to work with their css but I didnt change anything.
my question is there a possible way to put these html in a single .vm file??? if you know how to do it please help me, also if you need more info just ask me.
Are you talking about file diff? Where you check the differences in two files and merge them?
There is winmerge http://winmerge.org/
There is examdiff. Do a google search for file comparison or file diff