angular2 beta9:由Promise破坏的json管道?

时间:2016-03-08 23:13:13

标签: angular angular2-template

使用角度2 beta 9.

如果在plnkr中打开plnkr并使用json管道取消注释html,您将看到代码已损坏,您将在控制台中看到一些错误。

为方便起见,我在这里复制代码。

任何想法?

import {Component} from 'angular2/core';
import {NgIf} from 'angular2/common';

@Component({
  selector: 'my-app',
  template: `
    <div>

      <!-- This pipe breaks the code 
      <p>data promise: {{data | json}}</p> -->

      <p>data resolved: {{data|async}}</p>
      <button (click)="clicked()">Hello Promise</button>

      <div *ngIf="data|async"> 
        <p>data: {{data | json}}</p>
        Yes, The data is resolved: {{data|async}}
      </div>

    </div>
  `,
  directives: [NgIf]

})

export class AppComponent {
  data: Promise<string>;

  constructor() {
    this.data = new Promise((resolve,reject)=>{
      setTimeout(function() {
        resolve("Hello World from constrcutor ");
        }, 500)
        });
  }

  clicked() {
    this.data = new Promise((resolve,reject)=>{
      setTimeout(function() {
        resolve("Clicked");
        }, 500);
    });
  }
}

0 个答案:

没有答案