Placeholder on input not floating when projected from ng-content.
Placeholder must floating, when input has some value.
Placeholder looks like standard html placeholder, not like material placeholder.
StackBlitz: https://stackblitz.com/edit/angular-material2-issue-jekywv
Inability to use mat input with content projection.
latest
In console i have an error: mat-form-field must contain a MatFormFieldControl.
FYI it's not just the placeholder that has issues, this is completely unsupported right now, hence the errors
Have the same issue. This feature will extremely help me to reduce boilerplate html. @mmalerba, please, fix it! Thx
News?
I ended up using material-design-lite as a temporary solution, hope this gets resolved soon.
Are there any related issues to this one? This seems like a very glaring oversight that should've been fixed by now.
ERROR Error: mat-form-field must contain a MatFormFieldControl. same error, all modules working well, except this.
Hi, any comments on the status of this issue?
Mh.. this complicates things. Not using ng-content
but ngTemplateOutlet
, but that the same story I guess.
There has a dirty method is setting the matformFieldControl in the custom field component.
StackBlitz: https://stackblitz.com/edit/angular-material2-issue-rewh7v?file=app/field.component.ts
This is a rather glaring limitation. Hopefully it gets addressed soon.
I only get this error when I add the basic native select, but other work fine.
Waiting clear solutions...more than a year
"Waiting clear solutions...more than a year" me too!
ping @mmalerba
Is resolving this a consideration atm?
You need to import the MatInputModule into your app.module.ts file
A somewhat crude solution I found to bypass the issue
<mat-form-field>
<input matInput [hidden]="true">
<ng-container [ngTemplateOutlet]="content"></ng-container>
</mat-form-field>
Seems to work, although you should test carefully
You need to import the MatInputModule into your app.module.ts file
import { MatInputModule} from '@angular/material';
works fine for me thanks @claytoncc
I got this work by:
<mat-form-field>
<input matInput hidden>
<ng-content></ng-content>
</mat-form-field>
I didn't managed to make @qwe852147's solution work with version 9. So I came up with an even dirtier solution:
html:
<mat-form-field>
<ng-content></ng-content>
<!-- Placeholder control to fool mat-form-field -->
<ng-container *ngIf="beforeViewInit">
<input matInput/>
</ng-container>
</mat-form-field>
typescript:
export class FormFieldComponent implements AfterViewInit
beforeViewInit = true; // Used to remove placeholder control
@ContentChild(MatFormFieldControl) control: MatFormFieldControl<any>;
@ViewChild(MatFormField) matFormField: MatFormField;
constructor(private cdr: ChangeDetectorRef) {}
ngAfterViewInit() {
if (this.beforeViewInit) {
this.matFormField._control = this.control;
this.beforeViewInit = false;
this.cdr.detectChanges();
}
}
}
I just hope this issue will be addressed at some point to avoid this ugly / suboptimzed solution.
Import "MatFormFieldControl" in which component you want to use if you use a particular component.
import { Component, OnInit } from '@angular/core';
import {MatFormFieldModule,MatFormFieldControl} from '@angular/material/form-field';
@Component({
selector: 'app-bike',
templateUrl: './bike.component.html',
styleUrls: ['./bike.component.scss']
})
export class BikeComponent implements OnInit {
constructor() {
}
ngOnInit(): void {
}
}
This is a limitation of Angular's content projection. https://github.com/angular/angular/issues/37319 has been filed to hopefully improve some of the short-comings
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
_This action has been performed automatically by a bot._
Most helpful comment
Have the same issue. This feature will extremely help me to reduce boilerplate html. @mmalerba, please, fix it! Thx