Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

md-input-container must contain an mdInput directive?

I am using angular Material in my Angular 2 project while adding <md-input-container></md-input-container> i got this error:

md-input-container must contain an mdInput directive. Did you forget to add mdInput to the native input or textarea element?

I tried to solve this and googled it but didn't found any relevent answer for me. Please suggest me where I am doing wrong:

app.component.ts:

import { Component } from '@angular/core';

@Component({
  selector: 'my-app',
  template: `<h1>Hello {{name}}</h1>

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


styleUrls: [ './app/css/style.css' ],
})
export class AppComponent  { name = 'Angular'; }

app.module.ts:

import { NgModule                                     }   from '@angular/core';
import { BrowserModule                                }   from '@angular/platform-browser';
import { MaterialModule                               }   from '@angular/material';
import { AppComponent                                 }   from './app.component';
// import 'hammerjs';

@NgModule({
  imports:      [ MaterialModule.forRoot(),BrowserModule ],
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ]
})
export class AppModule { }

system.config.js:

(function (global) {
  System.config({
    paths: {
      'npm:': 'node_modules/'
    },
    map: {
      app: 'app',

      '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
      '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
      '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
      '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
      '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
      '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
      '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
      '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
      '@angular/material': 'npm:@angular/material/bundles/material.umd.js',

      'rxjs':                      'npm:rxjs',
      'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js'
    },
    packages: {
      app: {
        main: './main.js',
        defaultExtension: 'js'
      },
      rxjs: {
        defaultExtension: 'js'
      }
    }
  });
})(this);

index.html:

<!DOCTYPE html>
<html>
  <head>
    <title>Angular QuickStart</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="styles.css">
    <script src="node_modules/core-js/client/shim.min.js"></script>
    <link rel="stylesheet" href="node_modules/@angular/material/core/theming/prebuilt/deeppurple-amber.css">
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

    <script src="node_modules/zone.js/dist/zone.js"></script>
    <script src="node_modules/reflect-metadata/Reflect.js"></script>
    <script src="node_modules/systemjs/dist/system.src.js"></script>

    <script src="systemjs.config.js"></script>
    <script>
      System.import('app').catch(function(err){ console.error(err); });
    </script>
  </head>

  <body>
    <my-app>Loading AppComponent content here ...</my-app>
  </body>
</html>
like image 284
Shubham Verma Avatar asked Feb 16 '17 10:02

Shubham Verma


1 Answers

It's mdInput:

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

Check the Full Changelog with all breaking changes.

like image 163
developer033 Avatar answered Sep 21 '22 18:09

developer033