[英]TypeError: Cannot read property 'push' of undefined with AngularJS
[英]TypeError: Cannot read property 'push' of undefined - AngularJS
我將新事件“推送”到vm.events對象,並且不斷收到TypeError: Cannot read property 'push' of undefined
錯誤的TypeError: Cannot read property 'push' of undefined
。
我花了幾個小時在此上,但我沒有看到確切的未定義內容,每個元素似乎都有一個值。
這是我在記錄eventdata
時在控制台中看到的eventdata
:
Object
actions: Array[2]
color: Object
draggable: true
endsAt: Fri Dec 16 2016 08:00:00 GMT-0500 (Eastern Standard Time)
eventid: 457
resizable: true
startsAt: Fri Dec 16 2016 07:00:00 GMT-0500 (Eastern Standard Time)
title: "Asa Kris - Chris Brown "
__proto__: Object
js(請參閱vm.eventSaved函數)
var actions = [{
label: '<i class=\'glyphicon glyphicon-pencil\'></i>',
onClick: function(args) {
showEventModal('Edited', args.calendarEvent);
//alert.show('Edited', args.calendarEvent);
}
}, {
label: '<i class=\'glyphicon glyphicon-remove\'></i>',
onClick: function(args) {
vm.eventDeleted (args.calendarEvent)
//alert.show('Deleted', args.calendarEvent);
}
}
vm.events = [
{
title: 'An event',
color: calendarConfig.colorTypes.warning,
startsAt: moment().startOf('week').subtract(2, 'days').add(8, 'hours').toDate(),
endsAt: moment().startOf('week').add(1, 'week').add(9, 'hours').toDate(),
draggable: true,
resizable: true,
actions: actions
}, {
title: 'This is a really long event title that occurs on every year',
color: calendarConfig.colorTypes.important,
startsAt: moment().startOf('day').add(7, 'hours').toDate(),
endsAt: moment().startOf('day').add(19, 'hours').toDate(),
recursOn: 'year',
draggable: true,
resizable: true,
actions: actions
}
];
vm.eventSaved = function() {
var eventdata = {eventid : null,
title : newAppointmentCustomerId,
color : calendarConfig.colorTypes.info,
startsAt : new Date(vm.dtStart),
endsAt : new Date(vm.dtEnd),
draggable : true,
resizable : true,
actions : actions
};
var urlapieventspost = $location.protocol() + "://" + $location.host() + "/api/events";
$http.post(urlapieventspost, indata).success(function(data, status){
eventdata.eventid = data.id;
eventdata.title = data.eventtitle;
console.log(eventdata);
vm.events.push(eventdata);
}).error(function(err){
/* do something with errors */
});
};
vm.events
未定義。 由於它是唯一的對象,因此需要為其push
。 嘗試調試和記錄vm.events
。 如果顯示,則在聲明vm的地方也很有用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.