Angular 4 Typescript - Construct Array of Dates of subsequent 7 Days
I want construct an array of 7 dates. those dates will be 7 subsequent days from a SelectedDate. I have written following code in Component.ts
public selectedWeekDates: Date ;
public selectedWeek: Date = new Date();
SetSelectedWeekDates(): void {
var dte = new Date();
dte = this.selectedWeek;
for (let i: number = 1; i < 8; i++) {
this.selectedWeekDates[i - 1].setDate(dte.getDate() + i);
}
}
my html is as follows
.
.
.
<ng-container *ngFor="let dates of selectedWeekDates">
<div style="padding: 10px;">
{{ dates| date:"dd" }}
</div>
</ng-container>
.
.
.
I am getting below error in console
TypeError: Unable to get property '0' of undefined or null reference
at xxxComponent.prototype.SetSelectedWeekDates (eval code:179:143)
May I know what is wrong in my code?
angular typescript
add a comment |
I want construct an array of 7 dates. those dates will be 7 subsequent days from a SelectedDate. I have written following code in Component.ts
public selectedWeekDates: Date ;
public selectedWeek: Date = new Date();
SetSelectedWeekDates(): void {
var dte = new Date();
dte = this.selectedWeek;
for (let i: number = 1; i < 8; i++) {
this.selectedWeekDates[i - 1].setDate(dte.getDate() + i);
}
}
my html is as follows
.
.
.
<ng-container *ngFor="let dates of selectedWeekDates">
<div style="padding: 10px;">
{{ dates| date:"dd" }}
</div>
</ng-container>
.
.
.
I am getting below error in console
TypeError: Unable to get property '0' of undefined or null reference
at xxxComponent.prototype.SetSelectedWeekDates (eval code:179:143)
May I know what is wrong in my code?
angular typescript
I tried declaring it as public selectedWeekDates: Array<Date> = ;
– captainsac
Nov 20 at 6:52
try to check itfor (let i: number = 1; i < 8; i++) { if(this.selectedWeekDates[i - 1]){ this.selectedWeekDates[i - 1].setDate(dte.getDate() + i); } }
– Fateme Fazli
Nov 20 at 6:55
I guess you are accessing null element in your arraythis.selectedWeekDates[i - 1].setDate(dte.getDate() + i);, you should trythis.selectedWeekDates.push()
– Sarthak Aggarwal
Nov 20 at 6:57
@SarthakAggarwal No luck
– captainsac
Nov 20 at 7:15
add a comment |
I want construct an array of 7 dates. those dates will be 7 subsequent days from a SelectedDate. I have written following code in Component.ts
public selectedWeekDates: Date ;
public selectedWeek: Date = new Date();
SetSelectedWeekDates(): void {
var dte = new Date();
dte = this.selectedWeek;
for (let i: number = 1; i < 8; i++) {
this.selectedWeekDates[i - 1].setDate(dte.getDate() + i);
}
}
my html is as follows
.
.
.
<ng-container *ngFor="let dates of selectedWeekDates">
<div style="padding: 10px;">
{{ dates| date:"dd" }}
</div>
</ng-container>
.
.
.
I am getting below error in console
TypeError: Unable to get property '0' of undefined or null reference
at xxxComponent.prototype.SetSelectedWeekDates (eval code:179:143)
May I know what is wrong in my code?
angular typescript
I want construct an array of 7 dates. those dates will be 7 subsequent days from a SelectedDate. I have written following code in Component.ts
public selectedWeekDates: Date ;
public selectedWeek: Date = new Date();
SetSelectedWeekDates(): void {
var dte = new Date();
dte = this.selectedWeek;
for (let i: number = 1; i < 8; i++) {
this.selectedWeekDates[i - 1].setDate(dte.getDate() + i);
}
}
my html is as follows
.
.
.
<ng-container *ngFor="let dates of selectedWeekDates">
<div style="padding: 10px;">
{{ dates| date:"dd" }}
</div>
</ng-container>
.
.
.
I am getting below error in console
TypeError: Unable to get property '0' of undefined or null reference
at xxxComponent.prototype.SetSelectedWeekDates (eval code:179:143)
May I know what is wrong in my code?
angular typescript
angular typescript
asked Nov 20 at 6:49
captainsac
2,16921536
2,16921536
I tried declaring it as public selectedWeekDates: Array<Date> = ;
– captainsac
Nov 20 at 6:52
try to check itfor (let i: number = 1; i < 8; i++) { if(this.selectedWeekDates[i - 1]){ this.selectedWeekDates[i - 1].setDate(dte.getDate() + i); } }
– Fateme Fazli
Nov 20 at 6:55
I guess you are accessing null element in your arraythis.selectedWeekDates[i - 1].setDate(dte.getDate() + i);, you should trythis.selectedWeekDates.push()
– Sarthak Aggarwal
Nov 20 at 6:57
@SarthakAggarwal No luck
– captainsac
Nov 20 at 7:15
add a comment |
I tried declaring it as public selectedWeekDates: Array<Date> = ;
– captainsac
Nov 20 at 6:52
try to check itfor (let i: number = 1; i < 8; i++) { if(this.selectedWeekDates[i - 1]){ this.selectedWeekDates[i - 1].setDate(dte.getDate() + i); } }
– Fateme Fazli
Nov 20 at 6:55
I guess you are accessing null element in your arraythis.selectedWeekDates[i - 1].setDate(dte.getDate() + i);, you should trythis.selectedWeekDates.push()
– Sarthak Aggarwal
Nov 20 at 6:57
@SarthakAggarwal No luck
– captainsac
Nov 20 at 7:15
I tried declaring it as public selectedWeekDates: Array<Date> = ;
– captainsac
Nov 20 at 6:52
I tried declaring it as public selectedWeekDates: Array<Date> = ;
– captainsac
Nov 20 at 6:52
try to check it
for (let i: number = 1; i < 8; i++) { if(this.selectedWeekDates[i - 1]){ this.selectedWeekDates[i - 1].setDate(dte.getDate() + i); } }– Fateme Fazli
Nov 20 at 6:55
try to check it
for (let i: number = 1; i < 8; i++) { if(this.selectedWeekDates[i - 1]){ this.selectedWeekDates[i - 1].setDate(dte.getDate() + i); } }– Fateme Fazli
Nov 20 at 6:55
I guess you are accessing null element in your array
this.selectedWeekDates[i - 1].setDate(dte.getDate() + i);, you should try this.selectedWeekDates.push()– Sarthak Aggarwal
Nov 20 at 6:57
I guess you are accessing null element in your array
this.selectedWeekDates[i - 1].setDate(dte.getDate() + i);, you should try this.selectedWeekDates.push()– Sarthak Aggarwal
Nov 20 at 6:57
@SarthakAggarwal No luck
– captainsac
Nov 20 at 7:15
@SarthakAggarwal No luck
– captainsac
Nov 20 at 7:15
add a comment |
2 Answers
2
active
oldest
votes
In your function, you are using setDate function on elements of this.selectedWeekDates while they are undefined. You should use this.selectedWeek or dte to get and set your dates as below:
SetSelectedWeekDates(): void {
let dte: Date = new Date(this.selectedWeek);
for (let i = 1; i < 8; i++) {
this.selectedWeekDates[i-1]=new Date(dte.setDate(dte.getDate() + 1));
}
}
Also instead of adding i after getDate(), add 1 as done above as setDate() function is incrementing dte by a day in every iteration which means dte is updated after every iteration.
I displayed dte in Console Log. While using new Date() the log is Tue Nov 20 2018 14:21:29 GMT+0530 (India Standard Time) when this.selectedWeek is assigned dynamically from a database value then it is 2018-09-30T00:00:00. Does this have to do something with this issue?
– captainsac
Nov 20 at 8:55
It is because it is showing the default format returned bynew Date(). You can convert it to any other format you want. AssetDate()function updates the date it is called with but returns number in miliseconds so i converted it using new Date() in the loop for storing dates inthis.selectedWeekDates
– Nabil Shahid
Nov 20 at 9:05
Ifdteis showing today's date than it means thatthis.selectedWeekhas todays date instead of 2018-09-30T00:00:00 because of this line ` dte = this.selectedWeek;`.
– Nabil Shahid
Nov 20 at 9:14
@captainsac Good. Edited as you suggested.
– Nabil Shahid
Nov 20 at 9:19
Accepting this answer after multiple trial and edits
– captainsac
Nov 20 at 9:21
|
show 1 more comment
Your selectedWeekDates is empty. Hence the error. Give this a try to fix it:
public selectedWeekDates: Date = new Array(7).fill(new Date());
public selectedWeek: Date = new Date();
SetSelectedWeekDates(): void {
var dte = new Date();
dte = this.selectedWeek;
for (let i: number = 1; i < 8; i++) {
this.selectedWeekDates[i - 1].setDate(dte.getDate() + i);
}
}
This should fix the current error that you're getting. I'm not really sure what it is that you're trying to achieve here. So you might need to fix your logic a bit. All I'm able to see on the screen is 27, 7 times.
Here's a Sample StackBlitz for your ref.
Sorry but it is giving error ERROR TypeError: Object doesn't support property or method 'getDate'
– captainsac
Nov 20 at 7:28
Really? Not sure why, but I'm not able to see any such errors on the console. I just used the exact same logic as yours in theSetSelectedWeekDatesmethod.
– SiddAjmera
Nov 20 at 7:32
I displayed dte in Console Log. While using new Date() the log is Tue Nov 20 2018 14:21:29 GMT+0530 (India Standard Time) when this.selectedWeek is assigned dynamically from a database value then it is 2018-09-30T00:00:00. Does this have to do something with this issue?
– captainsac
Nov 20 at 8:59
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53387646%2fangular-4-typescript-construct-array-of-dates-of-subsequent-7-days%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
In your function, you are using setDate function on elements of this.selectedWeekDates while they are undefined. You should use this.selectedWeek or dte to get and set your dates as below:
SetSelectedWeekDates(): void {
let dte: Date = new Date(this.selectedWeek);
for (let i = 1; i < 8; i++) {
this.selectedWeekDates[i-1]=new Date(dte.setDate(dte.getDate() + 1));
}
}
Also instead of adding i after getDate(), add 1 as done above as setDate() function is incrementing dte by a day in every iteration which means dte is updated after every iteration.
I displayed dte in Console Log. While using new Date() the log is Tue Nov 20 2018 14:21:29 GMT+0530 (India Standard Time) when this.selectedWeek is assigned dynamically from a database value then it is 2018-09-30T00:00:00. Does this have to do something with this issue?
– captainsac
Nov 20 at 8:55
It is because it is showing the default format returned bynew Date(). You can convert it to any other format you want. AssetDate()function updates the date it is called with but returns number in miliseconds so i converted it using new Date() in the loop for storing dates inthis.selectedWeekDates
– Nabil Shahid
Nov 20 at 9:05
Ifdteis showing today's date than it means thatthis.selectedWeekhas todays date instead of 2018-09-30T00:00:00 because of this line ` dte = this.selectedWeek;`.
– Nabil Shahid
Nov 20 at 9:14
@captainsac Good. Edited as you suggested.
– Nabil Shahid
Nov 20 at 9:19
Accepting this answer after multiple trial and edits
– captainsac
Nov 20 at 9:21
|
show 1 more comment
In your function, you are using setDate function on elements of this.selectedWeekDates while they are undefined. You should use this.selectedWeek or dte to get and set your dates as below:
SetSelectedWeekDates(): void {
let dte: Date = new Date(this.selectedWeek);
for (let i = 1; i < 8; i++) {
this.selectedWeekDates[i-1]=new Date(dte.setDate(dte.getDate() + 1));
}
}
Also instead of adding i after getDate(), add 1 as done above as setDate() function is incrementing dte by a day in every iteration which means dte is updated after every iteration.
I displayed dte in Console Log. While using new Date() the log is Tue Nov 20 2018 14:21:29 GMT+0530 (India Standard Time) when this.selectedWeek is assigned dynamically from a database value then it is 2018-09-30T00:00:00. Does this have to do something with this issue?
– captainsac
Nov 20 at 8:55
It is because it is showing the default format returned bynew Date(). You can convert it to any other format you want. AssetDate()function updates the date it is called with but returns number in miliseconds so i converted it using new Date() in the loop for storing dates inthis.selectedWeekDates
– Nabil Shahid
Nov 20 at 9:05
Ifdteis showing today's date than it means thatthis.selectedWeekhas todays date instead of 2018-09-30T00:00:00 because of this line ` dte = this.selectedWeek;`.
– Nabil Shahid
Nov 20 at 9:14
@captainsac Good. Edited as you suggested.
– Nabil Shahid
Nov 20 at 9:19
Accepting this answer after multiple trial and edits
– captainsac
Nov 20 at 9:21
|
show 1 more comment
In your function, you are using setDate function on elements of this.selectedWeekDates while they are undefined. You should use this.selectedWeek or dte to get and set your dates as below:
SetSelectedWeekDates(): void {
let dte: Date = new Date(this.selectedWeek);
for (let i = 1; i < 8; i++) {
this.selectedWeekDates[i-1]=new Date(dte.setDate(dte.getDate() + 1));
}
}
Also instead of adding i after getDate(), add 1 as done above as setDate() function is incrementing dte by a day in every iteration which means dte is updated after every iteration.
In your function, you are using setDate function on elements of this.selectedWeekDates while they are undefined. You should use this.selectedWeek or dte to get and set your dates as below:
SetSelectedWeekDates(): void {
let dte: Date = new Date(this.selectedWeek);
for (let i = 1; i < 8; i++) {
this.selectedWeekDates[i-1]=new Date(dte.setDate(dte.getDate() + 1));
}
}
Also instead of adding i after getDate(), add 1 as done above as setDate() function is incrementing dte by a day in every iteration which means dte is updated after every iteration.
edited Nov 20 at 9:20
answered Nov 20 at 8:03
Nabil Shahid
51816
51816
I displayed dte in Console Log. While using new Date() the log is Tue Nov 20 2018 14:21:29 GMT+0530 (India Standard Time) when this.selectedWeek is assigned dynamically from a database value then it is 2018-09-30T00:00:00. Does this have to do something with this issue?
– captainsac
Nov 20 at 8:55
It is because it is showing the default format returned bynew Date(). You can convert it to any other format you want. AssetDate()function updates the date it is called with but returns number in miliseconds so i converted it using new Date() in the loop for storing dates inthis.selectedWeekDates
– Nabil Shahid
Nov 20 at 9:05
Ifdteis showing today's date than it means thatthis.selectedWeekhas todays date instead of 2018-09-30T00:00:00 because of this line ` dte = this.selectedWeek;`.
– Nabil Shahid
Nov 20 at 9:14
@captainsac Good. Edited as you suggested.
– Nabil Shahid
Nov 20 at 9:19
Accepting this answer after multiple trial and edits
– captainsac
Nov 20 at 9:21
|
show 1 more comment
I displayed dte in Console Log. While using new Date() the log is Tue Nov 20 2018 14:21:29 GMT+0530 (India Standard Time) when this.selectedWeek is assigned dynamically from a database value then it is 2018-09-30T00:00:00. Does this have to do something with this issue?
– captainsac
Nov 20 at 8:55
It is because it is showing the default format returned bynew Date(). You can convert it to any other format you want. AssetDate()function updates the date it is called with but returns number in miliseconds so i converted it using new Date() in the loop for storing dates inthis.selectedWeekDates
– Nabil Shahid
Nov 20 at 9:05
Ifdteis showing today's date than it means thatthis.selectedWeekhas todays date instead of 2018-09-30T00:00:00 because of this line ` dte = this.selectedWeek;`.
– Nabil Shahid
Nov 20 at 9:14
@captainsac Good. Edited as you suggested.
– Nabil Shahid
Nov 20 at 9:19
Accepting this answer after multiple trial and edits
– captainsac
Nov 20 at 9:21
I displayed dte in Console Log. While using new Date() the log is Tue Nov 20 2018 14:21:29 GMT+0530 (India Standard Time) when this.selectedWeek is assigned dynamically from a database value then it is 2018-09-30T00:00:00. Does this have to do something with this issue?
– captainsac
Nov 20 at 8:55
I displayed dte in Console Log. While using new Date() the log is Tue Nov 20 2018 14:21:29 GMT+0530 (India Standard Time) when this.selectedWeek is assigned dynamically from a database value then it is 2018-09-30T00:00:00. Does this have to do something with this issue?
– captainsac
Nov 20 at 8:55
It is because it is showing the default format returned by
new Date(). You can convert it to any other format you want. AssetDate() function updates the date it is called with but returns number in miliseconds so i converted it using new Date() in the loop for storing dates in this.selectedWeekDates– Nabil Shahid
Nov 20 at 9:05
It is because it is showing the default format returned by
new Date(). You can convert it to any other format you want. AssetDate() function updates the date it is called with but returns number in miliseconds so i converted it using new Date() in the loop for storing dates in this.selectedWeekDates– Nabil Shahid
Nov 20 at 9:05
If
dte is showing today's date than it means that this.selectedWeek has todays date instead of 2018-09-30T00:00:00 because of this line ` dte = this.selectedWeek;`.– Nabil Shahid
Nov 20 at 9:14
If
dte is showing today's date than it means that this.selectedWeek has todays date instead of 2018-09-30T00:00:00 because of this line ` dte = this.selectedWeek;`.– Nabil Shahid
Nov 20 at 9:14
@captainsac Good. Edited as you suggested.
– Nabil Shahid
Nov 20 at 9:19
@captainsac Good. Edited as you suggested.
– Nabil Shahid
Nov 20 at 9:19
Accepting this answer after multiple trial and edits
– captainsac
Nov 20 at 9:21
Accepting this answer after multiple trial and edits
– captainsac
Nov 20 at 9:21
|
show 1 more comment
Your selectedWeekDates is empty. Hence the error. Give this a try to fix it:
public selectedWeekDates: Date = new Array(7).fill(new Date());
public selectedWeek: Date = new Date();
SetSelectedWeekDates(): void {
var dte = new Date();
dte = this.selectedWeek;
for (let i: number = 1; i < 8; i++) {
this.selectedWeekDates[i - 1].setDate(dte.getDate() + i);
}
}
This should fix the current error that you're getting. I'm not really sure what it is that you're trying to achieve here. So you might need to fix your logic a bit. All I'm able to see on the screen is 27, 7 times.
Here's a Sample StackBlitz for your ref.
Sorry but it is giving error ERROR TypeError: Object doesn't support property or method 'getDate'
– captainsac
Nov 20 at 7:28
Really? Not sure why, but I'm not able to see any such errors on the console. I just used the exact same logic as yours in theSetSelectedWeekDatesmethod.
– SiddAjmera
Nov 20 at 7:32
I displayed dte in Console Log. While using new Date() the log is Tue Nov 20 2018 14:21:29 GMT+0530 (India Standard Time) when this.selectedWeek is assigned dynamically from a database value then it is 2018-09-30T00:00:00. Does this have to do something with this issue?
– captainsac
Nov 20 at 8:59
add a comment |
Your selectedWeekDates is empty. Hence the error. Give this a try to fix it:
public selectedWeekDates: Date = new Array(7).fill(new Date());
public selectedWeek: Date = new Date();
SetSelectedWeekDates(): void {
var dte = new Date();
dte = this.selectedWeek;
for (let i: number = 1; i < 8; i++) {
this.selectedWeekDates[i - 1].setDate(dte.getDate() + i);
}
}
This should fix the current error that you're getting. I'm not really sure what it is that you're trying to achieve here. So you might need to fix your logic a bit. All I'm able to see on the screen is 27, 7 times.
Here's a Sample StackBlitz for your ref.
Sorry but it is giving error ERROR TypeError: Object doesn't support property or method 'getDate'
– captainsac
Nov 20 at 7:28
Really? Not sure why, but I'm not able to see any such errors on the console. I just used the exact same logic as yours in theSetSelectedWeekDatesmethod.
– SiddAjmera
Nov 20 at 7:32
I displayed dte in Console Log. While using new Date() the log is Tue Nov 20 2018 14:21:29 GMT+0530 (India Standard Time) when this.selectedWeek is assigned dynamically from a database value then it is 2018-09-30T00:00:00. Does this have to do something with this issue?
– captainsac
Nov 20 at 8:59
add a comment |
Your selectedWeekDates is empty. Hence the error. Give this a try to fix it:
public selectedWeekDates: Date = new Array(7).fill(new Date());
public selectedWeek: Date = new Date();
SetSelectedWeekDates(): void {
var dte = new Date();
dte = this.selectedWeek;
for (let i: number = 1; i < 8; i++) {
this.selectedWeekDates[i - 1].setDate(dte.getDate() + i);
}
}
This should fix the current error that you're getting. I'm not really sure what it is that you're trying to achieve here. So you might need to fix your logic a bit. All I'm able to see on the screen is 27, 7 times.
Here's a Sample StackBlitz for your ref.
Your selectedWeekDates is empty. Hence the error. Give this a try to fix it:
public selectedWeekDates: Date = new Array(7).fill(new Date());
public selectedWeek: Date = new Date();
SetSelectedWeekDates(): void {
var dte = new Date();
dte = this.selectedWeek;
for (let i: number = 1; i < 8; i++) {
this.selectedWeekDates[i - 1].setDate(dte.getDate() + i);
}
}
This should fix the current error that you're getting. I'm not really sure what it is that you're trying to achieve here. So you might need to fix your logic a bit. All I'm able to see on the screen is 27, 7 times.
Here's a Sample StackBlitz for your ref.
answered Nov 20 at 7:16
SiddAjmera
12.3k21137
12.3k21137
Sorry but it is giving error ERROR TypeError: Object doesn't support property or method 'getDate'
– captainsac
Nov 20 at 7:28
Really? Not sure why, but I'm not able to see any such errors on the console. I just used the exact same logic as yours in theSetSelectedWeekDatesmethod.
– SiddAjmera
Nov 20 at 7:32
I displayed dte in Console Log. While using new Date() the log is Tue Nov 20 2018 14:21:29 GMT+0530 (India Standard Time) when this.selectedWeek is assigned dynamically from a database value then it is 2018-09-30T00:00:00. Does this have to do something with this issue?
– captainsac
Nov 20 at 8:59
add a comment |
Sorry but it is giving error ERROR TypeError: Object doesn't support property or method 'getDate'
– captainsac
Nov 20 at 7:28
Really? Not sure why, but I'm not able to see any such errors on the console. I just used the exact same logic as yours in theSetSelectedWeekDatesmethod.
– SiddAjmera
Nov 20 at 7:32
I displayed dte in Console Log. While using new Date() the log is Tue Nov 20 2018 14:21:29 GMT+0530 (India Standard Time) when this.selectedWeek is assigned dynamically from a database value then it is 2018-09-30T00:00:00. Does this have to do something with this issue?
– captainsac
Nov 20 at 8:59
Sorry but it is giving error ERROR TypeError: Object doesn't support property or method 'getDate'
– captainsac
Nov 20 at 7:28
Sorry but it is giving error ERROR TypeError: Object doesn't support property or method 'getDate'
– captainsac
Nov 20 at 7:28
Really? Not sure why, but I'm not able to see any such errors on the console. I just used the exact same logic as yours in the
SetSelectedWeekDates method.– SiddAjmera
Nov 20 at 7:32
Really? Not sure why, but I'm not able to see any such errors on the console. I just used the exact same logic as yours in the
SetSelectedWeekDates method.– SiddAjmera
Nov 20 at 7:32
I displayed dte in Console Log. While using new Date() the log is Tue Nov 20 2018 14:21:29 GMT+0530 (India Standard Time) when this.selectedWeek is assigned dynamically from a database value then it is 2018-09-30T00:00:00. Does this have to do something with this issue?
– captainsac
Nov 20 at 8:59
I displayed dte in Console Log. While using new Date() the log is Tue Nov 20 2018 14:21:29 GMT+0530 (India Standard Time) when this.selectedWeek is assigned dynamically from a database value then it is 2018-09-30T00:00:00. Does this have to do something with this issue?
– captainsac
Nov 20 at 8:59
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53387646%2fangular-4-typescript-construct-array-of-dates-of-subsequent-7-days%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I tried declaring it as public selectedWeekDates: Array<Date> = ;
– captainsac
Nov 20 at 6:52
try to check it
for (let i: number = 1; i < 8; i++) { if(this.selectedWeekDates[i - 1]){ this.selectedWeekDates[i - 1].setDate(dte.getDate() + i); } }– Fateme Fazli
Nov 20 at 6:55
I guess you are accessing null element in your array
this.selectedWeekDates[i - 1].setDate(dte.getDate() + i);, you should trythis.selectedWeekDates.push()– Sarthak Aggarwal
Nov 20 at 6:57
@SarthakAggarwal No luck
– captainsac
Nov 20 at 7:15