简体   繁体   English

Angular 2 材质“输入”占位符不在焦点上浮动

[英]Angular 2 Material 'Input' placeholder is not floating on focus

The placeholder in the textbox isn't floating on focus as shown in the screenshot below.文本框中的占位符没有浮动在焦点上,如下面的屏幕截图所示。 占位符不会浮动在焦点上

Click to view full screenshot点击查看完整截图

Here is my code:这是我的代码:

app.module.ts

import { BrowserModule } from '@angular/platform-browser';

import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { MatCheckboxModule, MatInputModule, MatListModule, MatCardModule, MatButtonModule, MdDatepickerModule, MdNativeDateModule, MatIconModule, MatTabsModule } from '@angular/material';
import { FormsModule,  ReactiveFormsModule } from '@angular/forms';


import { AppComponent } from './app.component';
import { AppRoutes } from './app.routes';

@NgModule({
  declarations: [
      AppComponent
  ],
  imports: [
      BrowserModule,
      RouterModule.forRoot(AppRoutes),
      BrowserAnimationsModule,
      MatCheckboxModule,
      MatInputModule,
      MatCardModule,
      MatButtonModule,
      MdDatepickerModule,
      MdNativeDateModule,
      MatIconModule,
      MatTabsModule,
      MatListModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

This is how I use it:这是我如何使用它:

login.component.html : login.component.html

<md-card>
    <md-card-header>
        <h2>Login</h2>
    </md-card-header>

    <md-card-content>
        <div class="divInput">
            <md-input-container>
                <input mdInput type="text" placeholder="Login ID">      
            </md-input-container>

        </div>
        <div class="divInput">
            <md-form-field>
                <input mdInput type="password" placeholder="Password">
            </md-form-field>
        </div>
    </md-card-content>
    <md-card-actions>
        <button md-button>LIKE</button>
    </md-card-actions>
</md-card>

Am I missing anything required?我是否缺少任何必需的东西? Could it be because I'm missing some required modules?可能是因为我缺少一些必需的模块吗?

I was facing the same issue, Add the below given import statement to style.css .我遇到了同样的问题,将下面给定的导入语句添加到style.css This have fixed my issue.这已经解决了我的问题。

@import '~@angular/material/prebuilt-themes/deeppurple-amber.css';

I guess this should solve your problem.我想这应该可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM