2016-03-27 23 views
0

私の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ライブラリがありますか?何か他のものに間違っていますか?

+0

あなたは 'SearchPipe'があるファイルがあることを確認しています'searchpipe'と呼ばれる? –

+0

はい、私は今パイプのディレクトリをapp/pipeに移動しましたが、現在はロードされていますが、メッセージが出ます。TypeError:nullのプロパティ 'filter'を読み取れません。 –

答えて

3

Pipeタイプはangular2/coreに含まれていますので、追加する必要はありません。

これは、おそらく、pipe/searchpipeをインポートするときに問題があると言われています。このモジュールを使用する場所からこのモジュールに到達するには、パスを確認する必要があります。

ほとんどの場合、モジュールをロードするときにエラーUnexpected token <(…)が404で発生します。

+0

他のアドレスを入力するとコンソールログに404が表示されます。したがって、モジュールがロードされています。私は角度2(ベータ12)を使用しています –

+0

私はすべてを修正しました。何らかの理由で、私はアプリのディレクトリからアプリケーションから分離することはできませんパイプフォルダを移動する必要がありました。 –

+1

私の場合は、Httpフォームの角度を使用しようとしているときにこのエラーが発生しました。実際、この ''のようなhttp jsファイルをインポートするのを忘れていました。 – Maxence

1

パイプ上のAnglar 2情報の一部が現在間違っています。

角度2のリリースが中に 'パイプ' 宣言を削除: @Component({ pipes: [YourPipe], ... })

そして(app.module.ts)にそれを移動: @NgModule({ ... declarations: [ YourPipe ], ... })

関連する問題