Angular 角度2-参考误差:';自定义类型';未定义-仅在一个模块中出错
我有一个Angular 2 CLI应用程序,其中包含多个延迟加载的模块。作为后端,我使用一个.NETAPI,它通过导出模型。我遇到的问题是,在一个模块中,类型定义可以正常工作,但在另一个模块中,当我浏览到该模块时,会出现引用错误 所引用的类型在介质模块内工作正常,但在位置模块内工作不正常。我不知道为什么,也找不到任何关于在哪里搜索错误的提示 使用angular cli时,应用程序编译时不会出错。但是,当我浏览或引用位置模块时,就会出现以下错误:Angular 角度2-参考误差:';自定义类型';未定义-仅在一个模块中出错,angular,typescript,angular-cli,typelite,Angular,Typescript,Angular Cli,Typelite,我有一个Angular 2 CLI应用程序,其中包含多个延迟加载的模块。作为后端,我使用一个.NETAPI,它通过导出模型。我遇到的问题是,在一个模块中,类型定义可以正常工作,但在另一个模块中,当我浏览到该模块时,会出现引用错误 所引用的类型在介质模块内工作正常,但在位置模块内工作不正常。我不知道为什么,也找不到任何关于在哪里搜索错误的提示 使用angular cli时,应用程序编译时不会出错。但是,当我浏览或引用位置模块时,就会出现以下错误: error_handler.js:60 Error
error_handler.js:60 Error: Uncaught (in promise): ReferenceError: TapeManager is not defined
ReferenceError: TapeManager is not defined
at Object.1477 (location-details.component.ts:2)
at __webpack_require__ (bootstrap 3623bc1…:52)
at Object.1452 (2.chunk.js:15)
at __webpack_require__ (bootstrap 3623bc1…:52)
at . async:27
at ZoneDelegate.invoke (zone.js:242)
at Object.onInvoke (ng_zone.js:271)
at ZoneDelegate.invoke (zone.js:241)
at Zone.run (zone.js:113)
at zone.js:535
at ZoneDelegate.invokeTask (zone.js:275)
at Object.onInvokeTask (ng_zone.js:262)
at ZoneDelegate.invokeTask (zone.js:274)
at Zone.runTask (zone.js:151)
at drainMicroTaskQueue (zone.js:433)
at resolvePromise (zone.js:501) [angular]
at resolvePromise (zone.js:486) [angular]
at vendor.bundle.js:174453:17 [angular]
at Object.onInvokeTask (ng_zone.js:262) [angular]
at ZoneDelegate.invokeTask (zone.js:274) [angular]
at Zone.runTask (zone.js:151) [<root> => angular]
at drainMicroTaskQueue (zone.js:433) [<root>]
我在媒体模块中还有一个组件,该组件对位置的引用与型号完全相同,但不会抛出错误:
import {Component, OnInit} from "@angular/core";
import {MediaService} from "./media.service";
import {Observable} from "rxjs";
import {MdSnackBar} from "@angular/material";
import Media = TapeManager.Models.Mediae.Media;
import Location = TapeManager.Models.Locations.Location;
@Component({
selector: 'app-media',
templateUrl: './media.component.html',
styleUrls: ['./media.component.scss'],
providers: [MdSnackBar]
})
export class MediaComponent implements OnInit {
public mediae: Observable<Media[]>;
public location: Location;
constructor(public mediaService: MediaService) {
}
ngOnInit(): void {
this.mediae = this.mediaService.getEntities();
}
}
引用的类型如下所示,位于tsconfig中类型根下引用的src/typings
内部
{
"compilerOptions": {
"baseUrl": "",
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [ "es7", "dom" ],
"mapRoot": "./src/",
"module": "es6",
"moduleResolution": "node",
"outDir": "dist/out-tsc",
"sourceMap": true,
"target": "es5",
"typeRoots": [
"node_modules/@types",
"src/typings"
]
},
"exclude": [
"dist",
"node_modules"
]
}
以下是TypeLite生成的类型定义示例:
/// <reference path="Enums.ts" />
...
declare module TapeManager.Models.Locations {
interface Address extends TapeManager.Models.Common.Entity {
additionalInformation: string;
city: string;
country: TapeManager.Models.Locations.Country;
formattedAddress: string;
postalCode: string;
state: string;
street: string;
streetNumber: string;
}
interface Coordinate {
latitude: number;
longitude: number;
}
interface Country extends TapeManager.Models.Common.Entity {
active: boolean;
alphaCode: string;
name: string;
numericCode: number;
}
interface Location extends TapeManager.Models.Common.Entity {
address: TapeManager.Models.Locations.Address;
coordinates: TapeManager.Models.Locations.Coordinate;
name: string;
}
interface LocationHistory extends TapeManager.Models.Common.Entity {
checkedIn: Date;
checkedInBy: TapeManager.Models.Users.Principal;
checkedInById: string;
checkedOut: Date;
checkedOutBy: TapeManager.Models.Users.Principal;
checkOutById: string;
location: TapeManager.Models.Locations.Location;
media: TapeManager.Models.Mediae.Media;
}
}
...
//
...
声明模块TapeManager.Models.Locations{
接口地址扩展TapeManager.Models.Common.Entity{
附加信息:字符串;
城市:字符串;
国家/地区:TapeManager.Models.Locations.country;
格式化地址:字符串;
后代码:字符串;
状态:字符串;
街道:字符串;
街道号码:字符串;
}
界面坐标{
纬度:数字;
经度:数字;
}
接口国家/地区扩展TapeManager.Models.Common.Entity{
活动:布尔值;
字母代码:字符串;
名称:字符串;
数字代码:数字;
}
接口位置扩展TapeManager.Models.Common.Entity{
地址:TapeManager.Models.Locations.address;
坐标:TapeManager.Models.Locations.Coordinate;
名称:字符串;
}
接口位置历史扩展TapeManager.Models.Common.Entity{
checkedIn:日期;
检查人:TapeManager.Models.Users.Principal;
checkedInById:字符串;
签出:日期;
checkedOutBy:TapeManager.Models.Users.Principal;
checkOutById:string;
位置:TapeManager.Models.Locations.location;
媒体:TapeManager.Models.Mediae.media;
}
}
...
我做错了什么?错误的原因是什么?我如何修复它?@Siluthus您有解决问题的方法吗?
{
"compilerOptions": {
"baseUrl": "",
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [ "es7", "dom" ],
"mapRoot": "./src/",
"module": "es6",
"moduleResolution": "node",
"outDir": "dist/out-tsc",
"sourceMap": true,
"target": "es5",
"typeRoots": [
"node_modules/@types",
"src/typings"
]
},
"exclude": [
"dist",
"node_modules"
]
}
/// <reference path="Enums.ts" />
...
declare module TapeManager.Models.Locations {
interface Address extends TapeManager.Models.Common.Entity {
additionalInformation: string;
city: string;
country: TapeManager.Models.Locations.Country;
formattedAddress: string;
postalCode: string;
state: string;
street: string;
streetNumber: string;
}
interface Coordinate {
latitude: number;
longitude: number;
}
interface Country extends TapeManager.Models.Common.Entity {
active: boolean;
alphaCode: string;
name: string;
numericCode: number;
}
interface Location extends TapeManager.Models.Common.Entity {
address: TapeManager.Models.Locations.Address;
coordinates: TapeManager.Models.Locations.Coordinate;
name: string;
}
interface LocationHistory extends TapeManager.Models.Common.Entity {
checkedIn: Date;
checkedInBy: TapeManager.Models.Users.Principal;
checkedInById: string;
checkedOut: Date;
checkedOutBy: TapeManager.Models.Users.Principal;
checkOutById: string;
location: TapeManager.Models.Locations.Location;
media: TapeManager.Models.Mediae.Media;
}
}
...