Components: hide/delete underline input

Created on 24 Aug 2017  路  5Comments  路  Source: angular/components

Bug

Property 'underlineRef' does not exist on type 'MdInputDirective'

However, underlineRef property exists if we log this MdInputDirective:

angularerror

Expected behavior

@ViewChild('input') input: MdInputDirective;

ngOnInit(): void {
  this.input.underlineRef.nativeElement.className = null;  // Removes the input underline 
}

What is the current behavior?

Compilation error

What are the steps to reproduce?

Link of a discussion on the issue:
https://stackoverflow.com/questions/45556972/how-to-hide-delete-underline-input-angular-material

Is there anything else we should know?

Workaround
@ViewChild('input') input: MdInputDirective;

ngOnInit(): void {
  this.input['underlineRef'].nativeElement.className = null;  // Remove the input underline 
}

Most helpful comment

Personally I'd opt for using css and leaving the underlineRef alone. I think the only reason it is exposed is for the datepicker to have a reference element to attach to, and I could easily see it going away or becoming internal-use-only.

I'd suggest a slight variation of your plunk:

// in global stylesheet
.mat-input-container.app-input-no-underline .mat-input-underline {
  display: none;
}
<md-input-container [class.app-input-no-underline]="!showUnderline">
  <input mdInput>
</md-input-container>

https://plnkr.co/edit/S8vHnOuzr6l6tYiMOnmi?p=preview

By adding it to a global stylesheet, you can keep view encapsulation on for your component.

All 5 comments

Reproduction? This working example is from that SO conversation:

https://plnkr.co/edit/XMhDIVBDup29sM8oi2dL?p=preview

@willshowell I had the same problem and I have archived this with ViewEncapsulation.None. What do you recommend?
https://plnkr.co/edit/Xxe8Wyv0141Ewxgcij4s?p=preview

Personally I'd opt for using css and leaving the underlineRef alone. I think the only reason it is exposed is for the datepicker to have a reference element to attach to, and I could easily see it going away or becoming internal-use-only.

I'd suggest a slight variation of your plunk:

// in global stylesheet
.mat-input-container.app-input-no-underline .mat-input-underline {
  display: none;
}
<md-input-container [class.app-input-no-underline]="!showUnderline">
  <input mdInput>
</md-input-container>

https://plnkr.co/edit/S8vHnOuzr6l6tYiMOnmi?p=preview

By adding it to a global stylesheet, you can keep view encapsulation on for your component.

Personally I'd opt for using css and leaving the underlineRef alone

Yep, I think the same.

And thanks for your tip! You are absolutely right

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._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RoxKilly picture RoxKilly  路  3Comments

Hiblton picture Hiblton  路  3Comments

kara picture kara  路  3Comments

vitaly-t picture vitaly-t  路  3Comments

3mp3ri0r picture 3mp3ri0r  路  3Comments