得到了这个错误,真的不明白为什么.. 我试图在角度日历上显示事件:https://mattlewis92.github.io/angular-calendar/#/async-events
error_handler.ts:1 ERROR TypeError:无法读取属性' map'的 未定义 在MapSubscriber.project(planning.component.ts:100) 在MapSubscriber._next(map.ts:75) 在MapSubscriber.Subscriber.next(Subscriber.ts:95) 在MapSubscriber._next(map.ts:80) 在MapSubscriber.Subscriber.next(Subscriber.ts:95) 在XMLHttpRequest.onLoad(xhr_backend.ts:99) 在ZoneDelegate.webpackJsonp.85.ZoneDelegate.invokeTask(zone-mix.js:424) at Object.onInvokeTask(ng_zone.ts:280) 在ZoneDelegate.webpackJsonp.85.ZoneDelegate.invokeTask(zone-mix.js:423) 在Zone.webpackJsonp.85.Zone.runTask(zone-mix.js:191)
component.ts
import { Component, ChangeDetectionStrategy, OnInit } from '@angular/core';
import { Http, URLSearchParams } from '@angular/http';
import { HttpClient } from '@angular/common/http';
import { CustomDateFormatter } from './custom-date-formatter.provider';
import 'rxjs/add/operator/map';
import { Observable } from 'rxjs/Observable';
interface Event {
id: number;
title: string;
start: string;
end: string;
}
events$: Observable<Array<CalendarEvent<{ event: Event }>>>;
constructor(private http: Http) { }
ngOnInit(): void {
this.fetchEvents();
}
fetchEvents(): void {
this.events$ = this.http
.get(this.apiUrl)
.map((response) => response.json())
.map(({ results }: { results: Event[] }) => {
return results.map((event: Event) => {
return {
title: event.title,
start: new Date(event.start),
end: new Date(event.end),
color: colors.yellow
};
});
});
}
来自api的json数据
[
{
"id": 2,
"user_id": 1,
"planning_id": 1,
"start": "2017-09-03T22:00:00.000Z",
"end": "2017-09-06T12:33:46.271Z",
"title": "A 3 day event",
"created_at": "2017-09-05 16:39:47",
"updated_at": "2017-09-05 16:39:47"
},
{
"id": 3,
"user_id": 1,
"planning_id": 1,
"start": "2017-09-03T22:00:00.000Z",
"end": "2017-09-06T12:33:46.271Z",
"title": "A 3 day event",
"created_at": "2017-09-07 13:27:36",
"updated_at": "2017-09-07 13:27:36"
}
]
答案 0 :(得分:3)
我知道它已经过时但我找到了一种方法可以使它与Angular 5一起使用
以这种方式宣布事件:
asyncEvents$: Observable<CalendarEvent[]>;
然后使用HttpClient加载数据
请注意,我的API返回了DateEvent
loadEvents() {
this.asyncEvents$ = this.http.get<DateEvent[]>(YOUR_URL)
.map(res => {
return res.map(event => {
return {
title: event.label,
start: new Date(event.startDate),
color: {primary: event.color, secondary: "#D1E8FF"},
meta: {
event
},
allDay: true
};
});
});
}
然后一切都按预期工作
答案 1 :(得分:0)
您必须导入地图运算符:
import 'rxjs/add/operator/map';
答案 2 :(得分:0)
答案 3 :(得分:0)
删除df1 = (df.set_index(['id','time'])
.applymap(lambda x: np.nan if x == [] else x)
.stack()
.astype(str)
.str.strip("[']")
.reset_index(name='new')
.rename(columns={'level_2':'cols'})
)
df1['g'] = df1['cols'].ne(df1.groupby('id')['cols'].shift()).cumsum()
df1 = (df1.groupby(['id','cols', 'g'])
.agg({'time':'first', 'new': ', '.join})
.reset_index(level=2, drop=True))
print (df1)
time new
id cols
A A 22222 aaaa
A 77777 a1a1a1
B 66666 aaaa
B 101111 a1a1a1
C 33333 ccccc
D 33333 sasasasasa, ddfdfdf
D 99999 ssdskd, sdsdsd
B A 120000 xxxx
B 543434 xxxx
C 443430 zzzz
并运行df1 = (df1.set_index(df1.groupby(level=[0,1]).cumcount(), append=True)
.unstack(1)
.reset_index(level=1, drop=True)
.rename(columns={'time':'data'}, level=0))
df1.columns = df1.columns.map('_'.join)
df1 = df1.reset_index()
print (df1)
id data_A data_B data_C data_D new_A new_B new_C \
0 A 22222.0 66666.0 33333.0 33333.0 aaaa aaaa ccccc
1 A 77777.0 101111.0 NaN 99999.0 a1a1a1 a1a1a1 NaN
2 B 120000.0 543434.0 443430.0 NaN xxxx xxxx zzzz
new_D
0 sasasasasa, ddfdfdf
1 ssdskd, sdsdsd
2 NaN
。它解决了我的问题
答案 4 :(得分:0)
就我而言,我不得不将 typescript
从 typescript@3.x.x
升级到 typescript@4.x.x
。
这个错误是怎么来的?我将我的 angular 应用从 angular@10
升级到 angular@11
。