我正在通过 @Input() -我需要使用迭代器进行操作,怎么做?
@Input()
这是我的代码:
@Input() events: Observable<Array<CalendarEvent>>; //required manipulation @Input() currentEvent: ModelEvent; clickedDate: Date; constructor(private calendarService:CalendarService) { } ngOnInit() { const headerHeight = $('.site-header').outerHeight(); //moving content down to header $('body').css({paddingTop: headerHeight}); this.calendarService.eventId.subscribe(event => { this.eventId = event.id; this.setViewDate(); }) // this.events.subscribe(data => console.log('data', data)); if(this.events.length) { //how to do? //at present getting error <!-- do something --> } }
你不能要求一个可观测的长度,因此你会得到一个错误相反,您应该订阅if语句,然后将其移动到回调函数中,在回调函数中,您可以使用事件的值来执行所需的操作。