我在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
我有一些逻辑来显示title
和subtitle
。但是我想从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;
}
我怎样才能获得这些属性?