我想在我的角度项目中添加钢系列。我有createad html-compass组件,但我收到了这个错误:
_services错误类型错误:无法读取未定义的属性(读取主题)在ProjectService…/app/Subject.js:53/_next(node_modules)在_esm5__tryOrUnsub[EventEmitter.push.](node_modules)在_esm5…/core.js.EventEmitter.emit/rxjs/core.js:3535/内部/node_modulesproject.service.ts.ProjectService.notifyToLoadHmi(_esm5)在_next…/project.service.ts:487/rxjs/SafeSubscriber.push./内部/node_modules(_esm5)在node_modules…/Subscriber.js.SafeSubscriber./rxjs/Subscriber.js:253/内部/SafeSubscriber.push.(node_modules)在_services…/Subscriber.js.SafeSubscriber.next/rxjs/Subscriber.js:191/内部/Subscriber.js.Subscriber.next(Subscriber.js:93)在EventEmitter.push.…/Subscriber.push./rxjs/_esm5/内部/Subject.js.Subject.next(core.js:1673)在project.service.ts.ProjectService.getLayoutTheme…/Subscriber.js:129/@角/核心/节日5/project.service.ts:311(header.component.ts:55)在ProjectService…/app/Subscriber.push./SafeSubscriber.schedulerFn(core.js:3563)
My html-compass.component.html:
<!DOCTYPE html>
<html>
<body>
<div (ngModelChange)="test()">
<canvas id="myCanvas"></canvas>
</div>
<script src="C:\\Virtual\\client\\node_modules\\steelseries\\srcdocs\\index.js"></script>
</body>
</html>
我的html-compass.component.ts:
import { Component, OnInit } from '@angular/core';
import { Compass } from "steelseries";
@Component({
selector: 'app-html-compass',
templateUrl: './html-compass.component.html',
styleUrls: ['./html-compass.component.css']
})
export class HtmlCompassComponent implements OnInit {
constructor() { }
static TypeTag = 'svg-ext-html_compass';
static LabelTag = 'HtmlCompass';
static prefixB = 'B-HXB_';
static prefixRect = 'svg_';
ngOnInit() {
}
test() {
const compass = new Compass(document.querySelector("#myCanvas"), {
size: 200
});
}
}
在项目服务中,我在函数中获取布局主题中的错误。可以在此处查看整个项目.service.ts 文件。
getLayoutTheme() {
return this.projectData.hmi.layout.theme;
}
在标头.component.ts(我收到错误的文件之一)中,代码是:
import { Component, Inject, ViewChild, OnInit, AfterViewInit, OnDestroy } from '@angular/core';
import { Router } from '@angular/router';
import { Subscription } from "rxjs";
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
import { environment } from '../../environments/environment';
import { SetupComponent } from '../editor/setup/setup.component';
import { ProjectService, SaveMode } from '../_services/project.service';
import { ThemeService } from '../_services/theme.service';
import { HelpData } from '../_models/hmi';
import { TutorialComponent } from '../help/tutorial/tutorial.component';
import { TranslateService } from '@ngx-translate/core';
@Component({
moduleId: module.id,
selector: 'app-header',
templateUrl: 'header.component.html',
styleUrls: ['header.component.css']
})
export class HeaderComponent implements OnInit, AfterViewInit, OnDestroy {
@ViewChild('sidenav')sidenav: any;
@ViewChild('tutorial') tutorial: TutorialComponent;
@ViewChild('fileImportInput') fileImportInput: any;
darkTheme = true;
ineditor = false;
savededitor = false;
private subscriptionShowHelp: Subscription;
private subscriptionLoad: Subscription;
constructor(private router: Router,
public dialog: MatDialog,
private translateService: TranslateService,
private themeService: ThemeService,
private projectService: ProjectService){
this.router.events.subscribe(()=> {
this.ineditor = (this.router.url.indexOf('editor') >= 0 || this.router.url.indexOf('device') >= 0 ||
this.router.url.indexOf('users') >= 0 || this.router.url.indexOf('text') >= 0 || this.router.url.indexOf('messages') >= 0|| this.router.url.indexOf('ReportDesigner') >= 0) ? true : false;
this.savededitor = (this.router.url.indexOf('device') >= 0 || this.router.url.indexOf('users') >= 0 ||
this.router.url.indexOf('text') >= 0 || this.router.url.indexOf('messages') >= 0|| this.router.url.indexOf('ReportDesigner') >= 0) ? true : false;
});
this.themeService.setTheme(this.projectService.getLayoutTheme());
}
ngOnInit() {
}
ngAfterViewInit() {
this.subscriptionLoad = this.projectService.onLoadHmi.subscribe(load => {
let theme = this.projectService.getLayoutTheme(); //AT THIS LINE THE ERROR OCCURS
this.darkTheme = (theme !== ThemeService.ThemeType.Default);
this.themeService.setTheme(this.projectService.getLayoutTheme());
}, error => {
console.log('Error loadHMI');
});
}
//...the rest of the code
我该怎么解决这个错误?
该项目在以下版本中运行:
Angular CLI:6.0.8节点:14.17.6操作系统:win32 x64 Angular:6.1.10…动画、通用、编译器、编译器-cli、核心、表单…超文本传输协议、语言服务、平台浏览器…平台浏览器动态、路由器
包版本-@ angular-devkit/architect 0 . 6 . 8 @ angular-devkit/build-angular 0 . 6 . 8 @ angular-devkit/build-optimizer 0 . 6 . 8 @ angular-devkit/core 0 . 7 . 5 @ angular/CDK 6 . 4 . 7 @ angular/CLI 6 . 0 . 8 @ angular/material 6 . 4 . 7 @ ngtools/web pack 6 . 0 . 8 @ schematics/angular 0 . 6 . 8 @ schematics/update 0 . 6 . 8 rx
好的,请这样试试
getLayoutTheme() {
return this.projectData?.hmi?.layout?.theme ? this.projectData?.hmi?.layout?.theme : '';
}
在setter方法中也是如此
setLayoutTheme(theme: string) {
this.projectData?.hmi?.layout?.theme = theme;
this.saveLayout();
}
我的代码: 错误: 未处理PromisejectionWarning:TypeError:无法读取未定义的未处理PromisejectionWarning:未处理的promise拒绝的属性“forEach”。此错误源于在没有catch块的情况下抛出异步函数的内部,或者拒绝使用未处理的promise。catch()。(拒绝id:1)(节点:7188)[DEP0018]弃用警告:未处理的promise
我试图使一个对话框弹出每当我得到一个错误从myerrorhandler我可以看到调用,但不是 这是我的错误消息。 错误类型错误:无法读取未定义的属性'openDialogTEST' 奇怪的是,如果我用按钮调用它,一切都很好。这是我的课程: usertable.component.ts auth.service.ts myerrorHandle.ts 对话框.component.ts 完整错误消息:
我正在选择area_enninFantry的所有子div,并循环调整某些子div的文本。cardArray是一个全局常量,myId在父函数中定义。 未捕获的TypeError:无法读取未定义的属性(读取“getAttribute”) 我在这篇文章中读到,这可能是因为字段/元素的内容可能是DOM元素,我应该用$()包装它们,所以我确实这样做了——将两个变量都更改为$(元素)[a]. attr(“标题
尝试使用< code>getAuth请求来存储令牌。请求不调用API并抛出错误。 TypeError:无法在HttpHeaders.push处读取undefined的属性(读取“length”)../node _ modules/@ angular/common/Fe sm5/http . js . http headers . apply update(http . js:199)at http
我遇到了一个有趣的问题,这使我感到困惑。我正在执行一个正确返回数据的Sharepoint RestAPI调用,当我在数据上运行for循环时,它生成html,但仍然抛出我用作标题的错误。代码如下。如果我记录每个循环,它将返回值。HTML也可以很好地工作。问题是错误仍然会出现。
在我的错误处理程序中,当我遇到错误时,我试图导航到另一个页面。 我尝试获取项目列表,如果失败,我想导航到“/error401”。我一直试图这样做: UserTablecomponent: 这个电话可能有点奇怪。它所做的是调用其余的,看看我有什么基于令牌的ID。然后在下一次调用中使用该ID 授权服务 迈勒手 这是我想导航到“/error401”的地方,但是 错误错误类型错误:无法读取未定义的属性“导