This seemed like something simple but for some reason I cant get this to work. So, I want the appearance of the mat-form-field to change based on some condition, for example, if the filed is disabled it should be none and if it is enabled it should be standard.
So for the most simple scenario, how to get this to work:
<mat-form-field appearance="'true' ? 'standard' : 'none'">
...
</mat-form-field>
This should work:
<mat-form-field [appearance]="true ? 'outline': 'fill'">
...
</mat-form-field>
Related
I'm using matInput. What I want is that the content in matInput is marked/highlighted so that if I press any key the text gets deleted. For example you double click a word in the search bar here in stackoverflow. How can I archieve that?
<mat-form-field>
<input matInput [(value)]="test">
</mat-form-field>
Assuming you're using Angular 8, you can use #ViewChild decorator to get a reference to your input element. Then you select the input value within the ngAfterViewInit lifecycle hook. In order to link the input element with #ViewChild, you can use a template reference variable (e.g. #food).
Please have a look at the following StackBlitz
Please note that using setTimeout inside ngAfterViewInit prevents you from getting an ExpressionChangedAfterItHasBeenCheckedError.
I am trying to use Mat-keyboard but the focus on input changes when I click the keyboard. Please see the image below -
displayed view of my keyboard
<form ngForm="myForm">
<mat-form-field>
<input matInput placeholder="Code" type="text" name="code">
</mat-form-field>
<mat-keyboard></mat-keyboard>
</form>
I want to achieve something this blog shows on angular 6:
Kindly visit to get more clarity
https://rawgit.com/GreenfieldVentures/angular-on-screen-keyboard/master/demo2.html
Thanks for your help!
You're not supposed to use <mat-keyboard> on it's own - it says so in the docs:
A component used to open as the default keyboard, matching material spec. This should only be used internally by the keyboard service.
Only use it as a directive:
<input matInput matKeyboard placeholder="Code" type="text" name="code">
You can read more on it on the docs site.
I am setting up an Angular project to use the Angular Material framework. I am also using materializecss. When I try to create a form, I get a double control shown below...
Here is how I am creating this field:
<mat-form-field hintLabel="Max 10 characters" appearance="standard">
<input matInput #input (keyup)="applyFilter($event.target.value)" placeholder="Filter catalogs">
</mat-form-field>
Use either Angular Material MatInput and MatFormField or MaterializeCSS, but not both. They both add their own style to input, causing the problem you see.
For Angular 5 + material library.
The core problem:
I have an input field that is supposed to accept a comma separated list of words. Some of these words could be from a pre-existing list and some could be completely new. So if the word happens to be from the pre-existing list, I want to allow autocomplete to complete it. I am not able to get this to happen. Any help would be greatly appreciated.
The separator could be something other than a comma.
I thought I saw a tutorial, mostly a work around somewhere that shows this. It wasn't exactly what I want to achieve. Unfortunately, I didn't save it. If anyone has this link, it would help.
This is my code as of now. It behaves more like a drop down, then like autocomplete
<mat-form-field>
<input matInput class="form-control" id="category" type="text"
formControlName="category"
[matAutocomplete]="auto" />
<mat-autocomplete #auto="matAutocomplete">
<mat-option *ngFor="let category of categories" [value]="category">{{category}}</mat-option>
</mat-autocomplete>
</mat-form-field>
I have mostly used the Material library, but I am not very satisfied documentation-wise. If mixing in an autocomplete component from a different library would work better, any pointers would be helpful
I am trying to bind color input using ng-model. In the following code:
<ul>
<li ng-repeat="col in ctrl.maincols">
<p>{{col.attr}}:{{col.value}}
<input type="color" ng-model="col.value"></p>
</li>
</ul>
there is no reaction when I select a colour. However if I change the input type to text everything works fine.
Any suggestions for making this work, or an alternative to ng-model for this use case?
It seems an editor for <input type="color"> is not yet implemented
see https://github.com/angular/angular.dart/blob/master/lib/directive/ng_model.dart
You could try to copy a similar and customize it to your needs.
You could also create a feature request. Please add a link here if you do.