Angular2解析器错误意外令牌

问题描述:

使用angular 2种子BS4创建angular2应用. 该组件使用管道,并且在我使用Angular2快速入门时有效,但是在使用

Creating an angular2 app using angular 2 seed BS4. The component uses a pipe and it worked when i was playing with the Angular2 Quickstart but doesnt when using Angular2-Seed-BS4

我跑步时得到:-

>     EXCEPTION: Template parse errors: Parser Error: Unexpected token | at column 32 in [ngFor let awsoffer of awsoffers| keys2] in
> AWSOfferListComponent@2:9 ("<h3>AWS Offer List Elements:</h3> <ul>  
> <table [ERROR ->]*ngFor="let awsoffer of awsoffers| keys2">
>     <th>{{awsoffer.key}}</th>
>     <div *ngFor="let awso2 o"): AWSOfferListComponent@2:9 Parser Error: Unexpected token . at column 28 in [ngFor let awso2 of
> awsoffer.value| keys2] in AWSOfferListComponent@4:9 ("   <table
> *ngFor="let awsoffer of awsoffers| keys2">
>     <th>{{awsoffer.key}}</th>
>     <div [ERROR ->]*ngFor="let awso2 of awsoffer.value| keys2">
>     <tr>
>     <td>{{awso2.key}}</td> "): AWSOfferListComponent@4:9

我已经在有角种子项目之外执行了此代码,因此在将逻辑移至结构内时必须出错—但是我看不到它是什么.搜索google似乎表明这与未加载管道模块有关,但似乎是-没有404错误.

I have had this code work outside of the angular-seed project so I must have something wrong when moving the logic to within the structure - but i cant see what it is. Searching google seems to indicate that its to do with the pipe module not being loaded but it appears that it is - no 404 errors.

组件:-

import { Component, OnInit } from 'angular2/core';
import { AWSOfferService } from '../../../shared/services/aws-offer.service';
import { AWSOffer } from './aws-offer';
import { KeysPipe } from '../../../shared/pipes/keys.pipe';
import { KeysMultPipe } from '../../../shared/pipes/keys2.pipe';




@Component({
  selector: 'aws-offer-list',
  templateUrl: './pages/aws-offers/components/aws-offer-list.html',
  styles: ['.th {color:red;}'],
  pipes : [KeysPipe, KeysMultPipe]
})

export class AWSOfferListComponent implements OnInit {
  constructor (private AWSOfferService: AWSOfferService) {}
  errorMessage: string;
  awsoffers: AWSOffer[];
  ngOnInit() { this.getAWSOffers(); }

  getAWSOffers() {
      this.AWSOfferService.getAWSOffers().subscribe(awsoffers => this.awsoffers = awsoffers,
                                        error =>  this.errorMessage = <any>error);
  }
}

模板:-

<h3>AWS Offer List Elements:</h3>
<ul>
  <table *ngFor="let awsoffer of awsoffers| keys2">
    <th>{{awsoffer.key}}</th>
    <div *ngFor="let awso2 of awsoffer.value| keys2">
    <tr>
    <td>{{awso2.key}}</td>
    <td>{{awso2.value}}</td>
    </tr>
    </div>
  </table>
</ul>

管道定义:-

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

@Pipe({name: 'keys2'})
export class KeysMultPipe implements PipeTransform {
  transform(value, args:string[]) : any {
    let keys = [];
    for (let key in value) {
      keys.push({key: key, value: value[key]});
    }
    return keys;
  }
}

项目结构的屏幕截图.

Screen shot of the project structure.

有什么想法吗?

预先感谢

只有使用beta.17版本,您才能编写:

Only with version beta.17 you can write:

<div *ngFor="let item of items">  // let instead of #

由于 Angular2-Seed-BS4 使用angular beta.2(

Since Angular2-Seed-BS4 uses angular beta.2 (https://github.com/start-angular/SB-Admin-BS4-Angular-2/blob/master/package.json#L90) you have to write like this:

<table *ngFor="#awsoffer of awsoffers | keys2">
...
<div *ngFor="#awso2 of awsoffer.value | keys2">

您可能对此链接感兴趣 https://github.com/angular/angular/blob/master/CHANGELOG.md#user-content-200-beta17-2016-04-28

This link may be of interest to you https://github.com/angular/angular/blob/master/CHANGELOG.md#user-content-200-beta17-2016-04-28