JS ERROR TypeError: value.getFullYear is not a function


#1

Hello everyone.
I practiced the example of TheNativeScriptBook / Chapter17 / PetScrapbookAngular and I’m stuck in the part where I need to implement the date picker in detail view. I wrote everything in the same code as in GitHub ( https://github.com/mikebranstein/TheNativeScriptBook/tree/master/Chapter17/PetScrapbookAngular/app/views/detail ), but I get an error: JavaScript error:
file: ///app/tns_modules/tns-core-modules/ui/date-picker/date-picker.js: 37: 39: JS ERROR TypeError: value.getFullYear is not a function. (In ‘value.getFullYear ()’, ‘value.getFullYear’ is undefined).

Did anyone have that error and how to fix it?

Thank you in advance.


#2

Thanks, gabra. We’re in the process of updating the book right now and saw this error. Stay tuned.


#3

After further investigation, I believe this is because a null value is being passed into the select-date modal dialog component. Checking for the null value and passing in today’s date can quickly remediate this. See below.

onBirthDateTap(): void {
		let options: ModalDialogOptions = {        
			context: this.page.BirthDate == null ? new Date() : this.page.BirthDate,            
			fullscreen: true,                        
			viewContainerRef: this.viewContainerRef  
		};                                         

		this.modalService.showModal(SelectDateComponent, options) 
			.then((dialogResult: any) => {                                     
				this.page.BirthDate = dialogResult;                              

				let now = Date.now();                                            
				let diff = Math.abs(now - this.page.BirthDate) / 1000 / 31536000;
				this.page.Age = diff.toFixed(1);                                 
			});                                                                
	}

#4

This will also be included in the book update.