错误类型错误:this._document.createElement 不是函数角度
Posted
技术标签:
【中文标题】错误类型错误:this._document.createElement 不是函数角度【英文标题】:ERROR TypeError: this._document.createElement is not a function angular 【发布时间】:2019-07-18 14:45:33 【问题描述】:我是 Angular 的新手,我正在使用 Angular 材质。我收到 mat-select 的跟随错误。我的代码如下
<mat-form-field>
<mat-select placeholder="Owner Type">
<mat-option value="Individual">Individual</mat-option>
<mat-option value="Corporate">Corporate</mat-option>
</mat-select>
</mat-form-field>
错误是:
ERROR Type Error: this._document.createElement is not a function
at n._createHostElement (main.6b5485aaca2669c7d428.js:1)
at n.create (main.6b5485aaca2669c7d428.js:1)
at n._createOverlay (main.6b5485aaca2669c7d428.js:1)
at n._attachOverlay (main.6b5485aaca2669c7d428.js:1)
at n.ngOnChanges (main.6b5485aaca2669c7d428.js:1)
at main.6b5485aaca2669c7d428.js:1
at main.6b5485aaca2669c7d428.js:1
at eu (main.6b5485aaca2669c7d428.js:1)
at ju (main.6b5485aaca2669c7d428.js:1)
at main.6b5485aaca2669c7d428.js:1
依赖关系
"dependencies":
"@agm/core": "^1.0.0-beta.5",
"@angular/animations": "^7.2.3",
"@angular/cdk": "^7.3.0",
"@angular/common": "^7.2.6",
"@angular/compiler": "~7.2.0",
"@angular/core": "~7.2.0",
"@angular/forms": "^7.2.6",
"@angular/http": "^7.2.2",
"@angular/material": "^7.3.3",
"@angular/platform-browser": "~7.2.0",
"@angular/platform-browser-dynamic": "~7.2.0",
"@angular/router": "~7.2.0",
"@types/jquery": "^3.3.29",
"angular-bootstrap-datetimepicker": "^2.2.1",
"bootstrap": "^3.4.1",
"core-js": "^2.5.4",
"datatables.net-bs4": "^1.10.19",
"font-awesome": "^4.7.0",
"hammerjs": "^2.0.8",
"ng-pick-datetime": "^5.2.6",
"rxjs": "^6.4.0",
"rxjs-compat": "^6.4.0",
"tslib": "^1.9.0",
"zone.js": "~0.8.26",
“开发依赖”: "@angular-devkit/build-angular": "~0.12.0", "@angular/cli": "~7.2.1", "@angular/compiler-cli": "~7.2.0", "@angular/language-service": "~7.2.0", "@types/node": "~8.9.4", "@types/jasmine": "~2.8.8", "@types/jasminewd2": "~2.0.3", "codelyzer": "~4.5.0", “茉莉花核”:“~2.99.1”, “茉莉花规格报告者”:“〜4.2.1”, "业力": "~3.1.1", "karma-chrome-launcher": "~2.2.0", “karma-coverage-istanbul-reporter”:“~2.0.1”, “业力茉莉花”:“〜1.1.2”, “karma-jasmine-html-reporter”:“^0.2.2”, "量角器": "~5.4.0", "ts-node": "~7.0.0", "tslint": "~5.11.0", “打字稿”:“~3.2.2”
请有人帮助我解决这个问题。
【问题讨论】:
您是否关闭了您的<mat-form-field>
?你的例子没有。尝试 AOT 编译时出现错误?
是的,我关闭了
@KartikS 你找到解决方案了吗?即使我按照“reza Torkaman Alhamdi”的建议导入 observable,我也面临同样的问题。
【参考方案1】:
我在这个应用程序中使用了第三方插件作为日期和时间选择器插件,它与所有材料冲突。现在我卸载了日期和时间选择器插件,现在它工作正常。
【讨论】:
【参考方案2】:只需在 ts 文件中添加一个数组,例如 ownerType = ["个人", "公司"]; 然后在 app.module.ts 中添加以下内容
import MatSelectModule from '@angular/material/select';
@NgModule(
imports: [ ..., MatSelectModule, ...]
)
<mat-form-field>
<mat-select placeholder="Owner Type">
<mat-option *ngFor="let owner of ownerType" [value]="owner">
owner
</mat-option>
</mat-select>
</mat-form-field>
【讨论】:
【参考方案3】:这可能是您导入Observable
的原因。
而不是这个import Observable from 'rxjs'
;试试这个:import Observable from 'rxjs/Observable'
;
【讨论】:
感谢您的回复。我做了同样的事情,但仍然面临同样的问题。以上是关于错误类型错误:this._document.createElement 不是函数角度的主要内容,如果未能解决你的问题,请参考以下文章
((Thermostat*)this)->Thermostat::_dht' 没有类类型
错误类型错误:this.route.params.flatMap 不是函数
错误 ||颤动 || 'owner!._debugCurrentBuildTarget == this': 不正确
TaskQueue:任务错误:未定义不是反应原生的对象(评估'_this.view._component.measureInWindow')