我用Angular创建了一个ASP.Net核心Web应用程序like in image。成功创建应用程序后,解决方案运行良好,输出完全来自浏览器。
之后,我将角度材料包含在上述项目中。下面是package.json
.{
"name": "WebApplication1",
"private": true,
"version": "0.0.0",
"scripts": {
"test": "karma start ClientApp/test/karma.conf.js"
},
"devDependencies": {
"@angular/animations": "5.0.2",
"@angular/common": "5.0.2",
"@angular/compiler": "5.0.2",
"@angular/compiler-cli": "5.0.2",
"@angular/core": "5.0.2",
"@angular/forms": "5.0.2",
"@angular/http": "5.0.2",
"@angular/platform-browser": "5.0.2",
"@angular/platform-browser-dynamic": "5.0.2",
"@angular/platform-server": "5.0.2",
"@angular/router": "5.0.2",
"@angular/cdk": "5.0.1",
"@angular/material": "^5.0.0-rc.3",
"@ngtools/webpack": "1.5.0",
"@types/chai": "4.0.1",
"@types/jasmine": "2.5.53",
"@types/webpack-env": "1.13.0",
"angular2-router-loader": "0.3.5",
"angular2-template-loader": "0.6.2",
"aspnet-prerendering": "^3.0.1",
"aspnet-webpack": "^2.0.1",
"awesome-typescript-loader": "3.2.1",
"bootstrap": "3.3.7",
"chai": "4.0.2",
"css": "2.2.1",
"css-loader": "0.28.4",
"es6-shim": "0.35.3",
"event-source-polyfill": "0.0.9",
"expose-loader": "0.7.3",
"extract-text-webpack-plugin": "2.1.2",
"file-loader": "0.11.2",
"html-loader": "0.4.5",
"isomorphic-fetch": "2.2.1",
"jasmine-core": "2.6.4",
"jquery": "3.2.1",
"json-loader": "0.5.4",
"karma": "1.7.0",
"karma-chai": "0.1.0",
"karma-chrome-launcher": "2.2.0",
"karma-cli": "1.0.1",
"karma-jasmine": "1.1.0",
"karma-webpack": "2.0.3",
"preboot": "4.5.2",
"raw-loader": "0.5.1",
"reflect-metadata": "0.1.10",
"rxjs": "5.5.5",
"style-loader": "0.18.2",
"to-string-loader": "1.1.5",
"typescript": "2.4.1",
"url-loader": "0.5.9",
"webpack": "2.5.1",
"webpack-hot-middleware": "2.18.2",
"webpack-merge": "4.1.0",
"zone.js": "0.8.18"
},
"dependencies": {
"@angular/cdk": "^5.0.1"
}
}
在使用npm安装角度材料后,我在app.server.module.ts中添加了所有角度/材质模块导入代码。如下所示:
import { MatFormFieldModule } from '@angular/material';
并将MatFormFieldModule导入NgModule。
我的HTML就像:
<mat-form-field>
<textarea matInput placeholder="Leave a comment"></textarea>
</mat-form-field>
最后,以下错误将在浏览器中出现:
“mat-form-field”是未知元素
请帮我简短一下这个问题。
将模块下方导入app.server.module.ts。
import { NgModule } from '@angular/core';
import { MatInputModule, MatFormFieldModule } from '@angular/material';
@NgModule({
imports: [
MatInputModule,
MatFormFieldModule
],
})
export class serverModule {
}
声明你的组件例如。 Index.component.ts如下所示声明到您的模块中。
@NgModule({
imports: [
MatInputModule,
MatFormFieldModule
],
declarations : [
IndexComponent.ts
]
})
export class serverModule {
}
然后进入你的Index.component.html写这个。
<form class="example-form">
<mat-form-field class="example-full-width">
<input matInput placeholder="Favorite food" value="Sushi">
</mat-form-field>
<mat-form-field class="example-full-width">
<textarea matInput placeholder="Leave a comment"></textarea>
</mat-form-field>
</form>
注意。在所有这些步骤之前,你应该将setup angular material纳入你的项目。
对于要在项目中使用的任何角度材料模块,应首先将其Mat ...模块导入到您正在使用的模块中。就像上面一样。