angularjs2尝试创建自定义管道

时间:2016-06-15 19:38:59

标签: angular

angularjs2新手试图在angularjs2中创建自定义管道获取错误

ReferenceError:管道未定义" "在https://github.com/mgechev/angular2-seed/issues"

报告此错误

// app.ts

import {Component, View, bootstrap} from 'angular2/angular2';
import {Box} from './components/box/box';
import { currentIndexPipe } from './pipes/currentIndex.Pipe';
import {approvedPrayers} from './services/approvedPrayers';


@Component({
    selector: 'app',   
     viewBindings: [approvedPrayers],


})

@View({
    templateUrl: './app.html',
    directives:  [Box],


})
class App {
}


bootstrap(App, [routerInjectables]);

// box.ts

import {Component, View,NgFor,Pipe,PipeTransform} from 'angular2/angular2';
import { approvedPrayers } from '../../services/approvedPrayers';
import { currentIndexPipe } from '../../pipes/currentIndexPipe';


@Component({
    selector: 'prayerbox'
})




@View({
        templateUrl: './components/box/box.html?v=<%= VERSION %>',
      directives: [NgFor],
pipes[currentIndexPipe]
})


export class Box {
 constructor(public list: approvedPrayers) {


    }


}

// currentIndexPipe.ts

import {Pipe, PipeTransform} from 'angular2/angular2';






@Pipe({
    name: 'currentIndex',

})

export class currentIndexPipe implements PipeTransform {

 transform(value: number,status) {
     return Array[value];

  }
}

请帮我解决这个问题,谢谢你

1 个答案:

答案 0 :(得分:0)

currentIndexPipe.ts 中的

,请更改您的

import {Pipe, PipeTransform} from 'angular2/angular2';

import {Pipe, PipeTransform} from '@angular/core';

因为angualr 2团队不久前改变了这个属性 有关更多信息,请参阅Pipe Documentation angualr 2
希望这会有所帮助。