gpt4 book ai didi

angular - 如何将 md-switch 添加到 Angular 4

转载 作者:太空狗 更新时间:2023-10-29 17:54:21 26 4
gpt4 key购买 nike

我想从 AngularJS Material 添加 md-switch到我的 angular4 项目,但出现以下错误:

Uncaught Error: Template parse errors:
'md-switch' is not a known element:
1. If 'md-switch' is an Angular component, then verify that it is part of this module.
2. If 'md-switch' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message

===============================

更新

测试.component.html:

<md-slide-toggle>Slide me!</md-slide-toggle>

测试.component.ts:

@Component({
selector: 'test',
templateUrl: './test.component.html',
styleUrls: ['./test.component.css']
})

测试.module.ts

import { MaterialModule, MdButtonModule, MdSlideToggleModule} from '@angular/material';
import { NgModule } from '@angular/core';
import { TestComponent } from './test.component';

@NgModule({
declarations: [
TestComponent
],
imports: [
MaterialModule, MdSlideToggleModule,
],
})
export class TestModule { }

包.json

{
"name": "web-app",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^4.0.0",
"@angular/common": "^4.0.0",
"@angular/compiler": "^4.0.0",
"@angular/core": "^4.0.0",
"@angular/forms": "^4.0.0",
"@angular/http": "^4.0.0",
"@angular/material": "^2.0.0-beta.7",
"@angular/platform-browser": "^4.0.0",
"@angular/platform-browser-dynamic": "^4.0.0",
"@angular/router": "^4.0.0",
"bootstrap": "^3.3.7",
"core-js": "^2.4.1",
"rxjs": "^5.1.0",
"zone.js": "^0.8.4"
},
"devDependencies": {
"@angular/cli": "1.1.3",
"@angular/compiler-cli": "^4.0.0",
"@angular/language-service": "^4.0.0",
"@types/jasmine": "2.5.45",
"@types/node": "~6.0.60",
"codelyzer": "~3.0.1",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~3.0.4",
"tslint": "~5.3.2",
"typescript": "~2.3.3"
}
}

我错过了什么?

最佳答案

您正在为 angular2 模块使用 angular1 库文档...

如果你已经有 this repo 安装只是将所需的功能从 Material 导入到您的模块,否则安装包:

npm install @angular/material

不要忘记在您选择的模块中包含功能组件模块:

测试.module.ts:

import {MatSlideToggleModule} from '@angular/material/slide-toggle';

imports: [ MatSlideToggleModule,

测试.component.html:

<mat-slide-toggle>Slide me!</mat-slide-toggle>

测试.component.ts:

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

@Component({
selector: 'test',
templateUrl: './test.component.html',
})
export class testComponent{}

关于angular - 如何将 md-switch 添加到 Angular 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44930785/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com