2017-02-16 114 views
4

我採用了棱角分明材料在我的角2項目,同時增加<md-input-container></md-input-container>我得到這個錯誤:md-input-container必須包含mdInput指令?

MD-輸入容器必須包含一個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> 
+0

我已經安裝了npm install -g angular-cli,npm install --save @ angular/material,在app.ts中導入了Angular Material NgModule,並且在SystemJS配置中添加了@ angular/material。現在缺少什麼? –

回答

5

這是mdInput

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

檢查Full Changelog所有重大更改。

+0

文檔示例說md-input,但mdInput是指令的正確名稱。 https://material.angular.io/components/component/input – hewstone

+0

是的,他們沒有更新它。 – developer033