根据这个示例带标签的表单字段,我试图更改mat-form-field
占位符的行为。有三个选项:auto
、always
和never
。
这个功能确实很好,可以根据开发人员想要实现的占位符类型来使用。
实际上,它可以全局使用,直接传递给应用程序根目录的@NgModule
:
@NgModule({
providers: [
{provide: MAT_LABEL_GLOBAL_OPTIONS, useValue: {float: 'always'}}
]
})
并按照以下方式构建视图:
<mat-form-field [floatLabel]="never"> // never, auto or always
<input matInput placeholder="Simple placeholder" required>
</mat-form-field>
我的问题是,我首先找不到/不知道在哪里可以/应该导入:
MAT_LABEL_GLOBAL_OPTIONS
,因为它似乎在@angular/material
中不存在。如果我在这个GitHub-Repo上检查,我会看到它是从@angular/material/core
中导入的,但它对我没有用,因为我得到了以下错误:
/node_modules/@angular/material/core"' has no exported member 'MAT_LABEL_GLOBAL_OPTIONS'. Did you mean 'MAT_RIPPLE_GLOBAL_OPTIONS'?
这与我使用的 material 和 CLI 版本有关吗?
Angular CLI: 1.5.0
Node: 8.0.0
OS: darwin x64
Angular: 5.0.3
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@angular/cdk: 5.0.0-rc.2
@angular/cli: 1.5.0
@angular/material: 5.0.0-rc.2
@angular-devkit/build-optimizer: 0.0.33
@angular-devkit/core: 0.0.21
@angular-devkit/schematics: 0.0.37
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.0
@schematics/angular: 0.1.7
typescript: 2.4.2
webpack: 3.8.1
import {MAT_LABEL_GLOBAL_OPTIONS} from "@angular/material";
。 - Xin Meng@angular/material
,因为你可以看到,我使用的是@angular/material: 5.0.0-rc.2
。 - k.vincent