微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Angular2解析器错误意外令牌

使用角度2种子BS4创建angular2应用程序.
该组件使用管道,当我使用Angular2快速入门时,它工作,但在使用 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

我已经在angular-seed项目之外使用了这个代码,所以在将逻辑移动到结构中时我必须有一些错误 – 但是我无法看到它是什么.搜索谷歌似乎表明它与管道模块没有加载,但它似乎是 – 没有404错误.

零件:-

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;
  }
}

项目结构的屏幕截图.

有任何想法吗?

提前致谢

只有版本为beta.17,你可以写:
<div *ngFor="let item of items">  // let instead of #

由于Angular2-Seed-BS4使用角度beta.2(https://github.com/start-angular/SB-Admin-BS4-Angular-2/blob/master/package.json#L90),你必须这样写:

<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

原文地址:https://www.jb51.cc/angularjs/142157.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐