Angular 4 错误:模板解析错误:没有带有“exportAs"的指令;设置为“matAutocomplete" [英] Angular 4 Error: Template parse errors: There is no directive with "exportAs" set to "matAutocomplete"

查看:22
本文介绍了Angular 4 错误:模板解析错误:没有带有“exportAs"的指令;设置为“matAutocomplete"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

升级到材料 2.0.0 beta 11 现在我有这个错误,我该如何解决它

<输入垫输入placeholder="{{'hotel.detail.labels.city' | 翻译 }}"[matAutocomplete]="tdAuto" name="city" #city="ngModel"[(ngModel)]="selected.city"(ngModelChange)="searchCity($event)"></mat-form-field><mat-autocomplete #tdAuto="mdAutocomplete"><mat-option (onSelectionChange)="setCity(city)"*ngFor="让城市之城" [value]="city.name"><div class="row"><span>{{city.name}} ({{city.province}})</span><span><small>{{city.region}}</small></span>

</mat-option></mat-autocomplete>

解决方案

更新:

在您的模板中,您使用的是 mdAutocomplete.将其更改为 matAutocomplete.

这一行:

到:

<小时>

app.module 或您使用材料模块的模块中,检查它们是否以 Mat 为前缀,而不是 Md.此外,模块 providers 条目中的 MATERIAL_COMPATIBILITY_MODE 提供程序.

在您的模块中导入以下内容:

从'@angular/material'导入{MATERIAL_COMPATIBILITY_MODE};

然后,将其添加为提供者:

@NgModule({供应商: [{提供: MATERIAL_COMPATIBILITY_MODE, useValue: true},//...],})

见这个CHANGELOG 和这个 前缀更新程序.链接到工作 StackBlitz 演示.

Ugrading to material 2.0.0 beta 11 now I have this errors, How can I fix it

<mat-form-field> <input matInput
    placeholder="{{'hotel.detail.labels.city' | translate }}"
    [matAutocomplete]="tdAuto" name="city" #city="ngModel"
    [(ngModel)]="selected.city"
     (ngModelChange)="searchCity($event)"> </mat-form-field>
    <mat-autocomplete #tdAuto="mdAutocomplete">
        <mat-option (onSelectionChange)="setCity(city)"
            *ngFor="let city of cities" [value]="city.name">
        <div class="row"><span>{{city.name}} ({{city.province}})</span> <span><small>{{city.region}}</small></span>
            </div>
    </mat-option> </mat-autocomplete>

解决方案

Update:

In your template, you are using mdAutocomplete. Change that to matAutocomplete.

This line:

<mat-autocomplete #tdAuto="mdAutocomplete">

to:

<mat-autocomplete #tdAuto="matAutocomplete">


In app.module or in your module where you are using material modules, check that they are prefixed with Mat and not Md. Also, the MATERIAL_COMPATIBILITY_MODE provider in module providers entry.

Import the following in your module:

import {MATERIAL_COMPATIBILITY_MODE} from '@angular/material';

And then, add it as a provider:

@NgModule({
  providers: [
    {provide: MATERIAL_COMPATIBILITY_MODE, useValue: true},
    // ...
  ],
})

See this CHANGELOG and this Prefix Updater. Link to working StackBlitz demo.

这篇关于Angular 4 错误:模板解析错误:没有带有“exportAs"的指令;设置为“matAutocomplete"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆