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

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

问题描述

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

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>

推荐答案

更新:

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

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

此行:

<mat-autocomplete #tdAuto="mdAutocomplete">

收件人:

<mat-autocomplete #tdAuto="matAutocomplete">


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


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},
    // ...
  ],
})

请参见 CHANGELOG 和此 前缀更新程序 .链接到有效的 StackBlitz演示 .

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

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

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