私のAngular 2プロジェクトで検索用のパイプを追加したいのですが、コンポーネントのブラウザログに作成されたパイプを含めると問題が発生します。予期しないトークン<(..)error 。 全ログ:Angular2パイプ - 予期しないトークン<(..)
angular2-polyfills.js:332
Error: SyntaxError: Unexpected token <(…)
ZoneDelegate.invoke @ angular2-polyfills.js:332Zone.run @ angular2-polyfills.js:227(anonymous function) @ angular2-polyfills.js:576Z
oneDelegate.invokeTask @ angular2-polyfills.js:365Zone.runTask @ angular2-polyfills.js:263drainMicroTaskQueue @ angular2-polyfills.js:482ZoneTask.invoke @ angular2-polyfills.js:434
は、ここに私のパイプコードです:
import {Pipe} from 'angular2/core';
@Pipe({
name: 'SearchPipe'
})
export class SearchPipe {
transform(items: any[], args: any[]): any {
return items.filter(item => item.name.indexOf(args[0]) != -1);
}
}
そしてここでコンポーネントのコードです。
import { Component, Directive } from 'angular2/core';
import {Http, HTTP_PROVIDERS} from 'angular2/http';
import {SearchPipe} from 'pipe/searchpipe';
import 'rxjs/Rx';
@Component({
pipes: [SearchPipe],
selector: 'MainPage',
templateUrl: 'app/mainpage/mainpage.html'
})
export class MainPageComponent {
korisnici: Object[];
constructor(http: Http){
http.get('korisnici.json')
.map(res => res.json())
.subscribe(korisnici => this.korisnici = korisnici);
}
}
これらのエラーは、前回私がhttp.dev.jsライブラリを追加せずにhttpを使用していたときに起こったものです。パイプを含むJSライブラリがありますか?何か他のものに間違っていますか?
あなたは 'SearchPipe'があるファイルがあることを確認しています'searchpipe'と呼ばれる? –
はい、私は今パイプのディレクトリをapp/pipeに移動しましたが、現在はロードされていますが、メッセージが出ます。TypeError:nullのプロパティ 'filter'を読み取れません。 –