Angular 2找不到名称SimpleChanges

时间:2017-01-25 09:45:48

标签: angular typescript timer

编译代码时出现此错误:找不到名称SimpleChanges。我是Angular 2的新手,你能帮我找到错误的位置吗? 这是我的家。:

import { Component } from '@angular/core';

import { NavController } from 'ionic-angular';
import {Observable} from 'rxjs/Rx';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  date: Date;
  constructor(public navCtrl: NavController) {
    this.date = new Date();
  }


  ticks = 0;
  ngOnChanges(changes: {[propertyName: string]: SimpleChanges}){
    if(changes['ticks']){
        if(this.ticks == 20)
            this.ticks = 0;
    }
  }
  ngOnInit(){
    let timer = Observable.timer(0,1000);
    timer.subscribe(t=>this.ticks = t);
  };



}

1 个答案:

答案 0 :(得分:17)

您忘记从SimpleChanges导入@angular/core界面。

import { SimpleChanges } from '@angular/core';