Angular 2尝试使用单个文件导入TS类时出错

时间:2016-04-27 19:53:14

标签: typescript angular

加载我的angular 2应用程序时出现以下错误:

EXCEPTION: Error: Uncaught (in promise): Unexpected piped value 'undefined' on the View of component 'DashboardComponent'

奇怪的是,如果我取消注释此行并从“appCore”中删除“CustomPipe”引用,它将再次起作用:

//import {CustomPipe} from "../shared/customPipe"

这让我想知道在使用我的“父”导出文件“appCore.ts”时我是不是正确导入/导出类,或者是否存在角度2的某些问题。

我做错了吗?

Example Project on Github

CustomPipe.ts

import {Pipe, PipeTransform} from "angular2/core"

@Pipe({ name: "CustomPipe" })
export class CustomPipe implements PipeTransform
{
    constructor()
    {
        console.log("created");
    }
    public transform(value: string, args: any[]): string
    {
        return "this value has been transformed into me via a custom pipe";
    }
}

appCore.ts

export * from "./dashboard/dashboardComponent"
export * from "./vehicles/VehicleListComponent"
export * from "./vehicles/VehicleComponent"
export * from "./shared/nestedComponent"
export * from "./interfaces/IVehicleService"
export * from "./shared/staticVehicleService"
export * from "./shared/VehicleService"
export * from "./shared/customPipe"

dashboardComponent.ts

import {Component, Output, EventEmitter, OnInit, Inject, Injectable, provide, OpaqueToken} from "angular2/core"
import {CustomPipe, IVehicleService, StaticVehicleService} from "../appCore"
//import {CustomPipe} from "../shared/customPipe"
import {NestedComponent} from "../shared/nestedComponent"
import {Observable} from "rxjs/Rx"
import {IVehicleServiceToken} from "../interfaces/IVehicleService"

@Component({
    selector: "my-app",
    templateUrl: "./app/dashboard/dashboardComponent.html",
    styleUrls: ["./app/dashboard/dashboardComponent.css"],
    directives: [NestedComponent],
    pipes: [CustomPipe]
})
export class DashboardComponent implements OnInit
{
}  

修改 Here is a Plunker of the issue: 查看app / characters / character-list.component.ts第5行& 6.插件不起作用,但如果取消注释第6行并从第5行删除“CharacterService”,它将起作用。

2 个答案:

答案 0 :(得分:0)

代码看起来不错。我试图在我的应用程序中复制,无论我做什么,我都无法得到你的错误 我认为你可能对Angular2有一些过时的依赖,我建议将每个包更新到最新的支持。

使用错误的npm依赖项版本时,可以找到类似的错误hereUnexpected piped value 'undefined' on the View of component

答案 1 :(得分:0)

我遇到了同样奇怪的错误(angular-2-0.0.rc4)。 我最后一次导入是我的管道,并通过向上移动导入线,错误消失了。我不知道为什么。您是否尝试过移动管道导入线?

我知道这没有任何意义,但它解决了我的问题。