Error while using md-input-container

2.9k views Asked by At

I have created a Angular 2 material app as per link https://github.com/angular/material2/blob/master/GETTING_STARTED.md.

I am able to use <md-card>, <md-toolbar>, <md-input> etc. But when I use <md-input-container>, it is throwing error as

zone.js:388 Unhandled Promise rejection: Template parse errors:
'md-input-container' is not a known element:

Here are the detail from packages.json,

"dependencies": {
    "@angular/common": "~2.1.0",
    "@angular/compiler": "~2.1.0",
    "@angular/core": "~2.1.0",
    "@angular/forms": "~2.1.0",
    "@angular/http": "~2.1.0",
    "@angular/material": "^2.0.0-alpha.11-3",
    "@angular/platform-browser": "~2.1.0",
    "@angular/platform-browser-dynamic": "~2.1.0",
    "@angular/router": "~3.1.0",
    "core-js": "^2.4.1",
    "hammerjs": "^2.0.8",
    "ng2-file-upload": "^1.1.4-2",
    "rxjs": "5.0.0-beta.12",
    "ts-helpers": "^1.1.1",
    "zone.js": "^0.6.23"
  },

How I can fix this?

https://github.com/angular/material2/tree/master/src/lib/input says that md-input is deprecated and use md-input-container.

2

There are 2 answers

2
j809809jkdljfja On BEST ANSWER

I think it might not work yet, because those changes didn't made into 2.0.0-alpha.11 release yet.

https://github.com/angular/material2/compare/2.0.0-alpha.11...master

We will have to wait till the next release for npm to cointain this, but I am not sure about that.

0
edkeveked On

This worked for me.

app.module.ts

import { MaterialModule } from '@angular/material';
...
@NgModule({
imports: [
MaterialModule
]
})

app.component.html

<md-input-container>
<input mdInput placeholder="Favorite food" value="Sushi">
</md-input-container>

The key thing here is to make sure that you add this in the head of your index.html.

<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">