在最初的实现和输入终端 ng 后,我有成千上万的这个错误,我不能解决它。这是我第一次当我有这样的问题,内角与打字稿 错误是这样的:
错误 . . . ./node _ module/@angle/flex-layp/core/typeings/base/base2.d.ts: 24:19 - 错误 TS1086: 无法在环境上下文中声明访问器。
24 protected get parentElement(): HTMLElement | null; ~~~~~~~~~~~~~ ../../node_modules/@angular/flex-layout/core/typings/base/base2.d.ts:26:19
- 错误 TS1086: 无法在环境上下文中声明访问器。
26 protected get nativeElement(): HTMLElement; ~~~~~~~~~~~~~ ../../node_modules/@angular/flex-layout/core/typings/base/base2.d.ts:28:9
- 错误 TS1086: 无法在环境上下文中声明访问器。
28 get activatedValue(): string; ~~~~~~~~~~~~~~ ../../node_modules/@angular/flex-layout/core/typings/base/base2.d.ts:29:9
- 错误 TS1086: 无法在环境上下文中声明访问器。
29 set activatedValue(value: string); ~~~~~~~~~~~~~~ ../../node_modules/@angular/flex-layout/core/typings/breakpoints/break-point-registry.d.ts:20:9
- 错误 TS1086: 无法在环境上下文中声明访问器。
[...]
有人知道为什么吗? 我不能测试我的应用程序,直到我修复它。
好吧,我直说了。大多数错误已经消失了,但是我现在有几个错误,比如第一个:
Src/app/main/main.Component. ts 中的错误: 143:63-ERROR TS2322: Type 字符串 | 未定义’不能赋值给字符串类型 “ unDefinition”不能赋值给“ string”类型。
Add ({ isFolder: true,name: folder.name, this.currentRoot.id : ‘ root’}) ;
代码如下:
Main.component.ts:
currentRoot: MpFileElement = new MpFileElement();
...
addFolder(folder: { name: string }) {
this.fileService.add({ isFolder: true, name: folder.name, parent:
this.currentRoot ? this.currentRoot.id : 'root' });
this.updateFileElementQuery();
}
...
File.service.ts:
import { Injectable } from '@angular/core';
import { v4 } from 'uuid';
import { MpFileElement } from '../models/mp-file-element.model';
import { Observable } from 'rxjs/internal/Observable';
import { BehaviorSubject } from 'rxjs';
export interface IFileService {
add(fileElement: MpFileElement);
delete(id: string);
update(id: string, update: Partial<MpFileElement>);
queryInFolder(folderId: string): Observable<MpFileElement[]>;
get(id: string): MpFileElement;
}
@Injectable()
export class MpFileService implements IFileService {
constructor() {}
private map = new Map<string, MpFileElement>()
private querySubject: BehaviorSubject<MpFileElement[]>;
add(fileElement: MpFileElement) {
fileElement.id = v4();
this.map.set(fileElement.id, this.clone(fileElement));
return fileElement;
}
delete(id: string) {
this.map.delete(id);
}
update(id: string, update: Partial<MpFileElement>) {
let element = this.map.get(id);
element = Object.assign(element, update);
this.map.set(element.id, element);
}
queryInFolder(folderId: string) {
const result: MpFileElement[] = [];
this.map.forEach(element => {
if (element.parent === folderId) {
result.push(this.clone(element));
}
})
if (!this.querySubject) {
this.querySubject = new BehaviorSubject(result);
} else {
this.querySubject.next(result);
}
return this.querySubject.asObservable();
}
get(id: string) {
return this.map.get(id);
}
clone(element: MpFileElement) {
return JSON.parse(JSON.stringify(element));
}
}