Angular 4 Error: Template parse errors: There is n

2019-05-15 23:18发布

问题:

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>

回答1:

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.