This is my function. In here I want to filter object from an array and pass it in to the note variable When I run the program its shows var note variable is undefined what can I do for that
Review below code
datepicker.onSelect = function (checked) {
var state = (checked) ? 'selected' : 'unselected';
$scope.calDate = this.toLocaleDateString();
var note = $scope.tooltipsArray.filter(function (items) { return items.date === '$scope.calDate' })[0];
ModalService.showModal({
templateUrl: 'scripts/directives/calendar/calendarModal.html',
controller: 'calendarModal',
inputs: {
calendarDate: $scope.calDate,
calendarNote: null,
dateSelected: state
},
size: 'sm'
}).then(function (modal) {
modal.element.modal();
});
};
One issue I can see in your code is you are using $scope.calDate as string
change '$scope.calDate' to $scope.calDate
var note = $scope.tooltipsArray.filter(function (items) { return items.date === $scope.calDate })[0];
And Also to get the current localeDateString , use the below code
$scope.calDate = new Date().toLocaleDateString();
Stack Blitz
https://stackblitz.com/edit/angularjs-szy529?file=home/home.controller.js
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.