从通过@Input

时间:2017-07-31 21:42:58

标签: javascript angular typescript

我在app.component.ts中创建了一个简单的对象数组:

 zippyPost = [
      { title: 'Shipping Details',subtitle: 'Shipping Details Content' },
      { title: 'Billing Details',subtitle: 'Billing Details Content' }
  ]

传递给zippy component中的app.componenet.html,如:

<zippy-element [post] = "zippyPost"></zippy-element>

然后在zippy.html我有一些逻辑来显示titlesubtitle。但是我想从title获取一个zippy component属性,看起来:

export class ZippyElementComponent implements OnInit, OnChanges  {
  @Input('post') post: any;
  expand: boolean;

  constructor() { 
  }

  ngOnInit() {
  }

   ngOnChanges(changes: SimpleChanges) {
    // changes.prop contains the old and the new value...
    console.log('hello', changes.post.currentValue);
  }

  expanded(title : string){
    console.log('mmm', this.post)
    for(let i in this.post){
      if(title === i.title){ <- here it is an error which says : [ts] Property 'title' does not exist on type 'string'.
        console.log('im in if');
        this.post['ok'] = true;
      }
    }
   // this.expand = !this.expand;
  }

我怎样才能获得这些属性?

0 个答案:

没有答案