使用NgDoCheck检测对象属性键更改

时间:2017-06-15 10:45:23

标签: angular typescript typescript2.0

我有以下......

ngDoCheck() {
    let changes = this.differ.diff( this.immunization )

    if ( changes ) {
      changes.forEachChangedItem( r => {
        /// previously worked API
        console.log( r.currentValue.keys )  /// does not work
        console.log( r.key )  /// does not work

        console.log( 'changes detected' )
        changes.forEachChangedItem( r => console.log( 'changed ', r.currentValue ) )      
      } )

//      changes.forEachChangedItem( ( elt ) => {
//        switch ( elt.key ) {
//          case 'disease':
//            console.log( 'Disease has changed' )
//        }
//
//      } )
    }
  }

我试图获取随ngDoCheck()更改的属性的键,但在上面的代码中没有太大成功。任何帮助表示赞赏

编辑1

export class Immunization {
  disease: string
}

immunization = new Immunization() // r logs immunization property change

0 个答案:

没有答案