md-input-container必须包含mdInput指令?

时间:2017-02-16 10:26:34

标签: angular typescript material-design angular-material

我在Angular 2项目中使用angular Material,同时添加<md-input-container></md-input-container>我收到此错误:

md-input-container必须包含mdInput指令。您是否忘记将mdInput添加到本机输入或textarea元素?

我试图解决这个问题并用Google搜索,但没有为我找到任何相关的答案。 请建议我在哪里做错了:

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>

1 个答案:

答案 0 :(得分:5)

这是mdInput

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

检查Full Changelog所有重大更改。