Dynamically show / hide a component if its date is not between 2 other dates
I have two inputs: <input type="date" id="fromDate">
and <input type="date" id="toDate">
, and then a *ngFor
loop iterating through a list of items. All of these items have a property activity_date
.
I want to be able to only show the components having their activity_date
property between the dates of fromDate
and toDate
. For this, I am using MomentJS, more precisely the function moment(activity_date).isBetween(fromDate, toDate)
.
The problem here is I want to assign the result of the previous method to a [hidden]
attribute so if an input
is changed, the [hidden]
property will be updated.
But here's the catch. How can I do to show / hide the components whenever the inputs
are changed ?
Here's what I've tried so far:
view.component.html
<app-events
type="calendar-item"
[hidden]="moment(item.activity_date).isBetween(this.fromDate, this.toDate);"
[data]="item"
></app-events>
view.component.ts
import Component, OnInit from "@angular/core";
import * as moment from "moment";
@Component(
selector: "app-view",
templateUrl: "./view.component.html",
styleUrls: ["./view.component.css"]
)
export class ViewComponent implements OnInit
fromDate: string;
toDate: string;
item = [
id: 1,
activity_date: "14 November 2018",
];
ngOnInit()
isBetweenDate(date: string)
return moment(date).isBetween(this.fromDate, this.toDate);
It works if I write values in the method by hand, and it only works at the loading of the page.
I was trying to look after the EventEmitter
or the Custom Attributes, but I'm not sure I am moving to the right direction.
javascript angular momentjs
add a comment |
I have two inputs: <input type="date" id="fromDate">
and <input type="date" id="toDate">
, and then a *ngFor
loop iterating through a list of items. All of these items have a property activity_date
.
I want to be able to only show the components having their activity_date
property between the dates of fromDate
and toDate
. For this, I am using MomentJS, more precisely the function moment(activity_date).isBetween(fromDate, toDate)
.
The problem here is I want to assign the result of the previous method to a [hidden]
attribute so if an input
is changed, the [hidden]
property will be updated.
But here's the catch. How can I do to show / hide the components whenever the inputs
are changed ?
Here's what I've tried so far:
view.component.html
<app-events
type="calendar-item"
[hidden]="moment(item.activity_date).isBetween(this.fromDate, this.toDate);"
[data]="item"
></app-events>
view.component.ts
import Component, OnInit from "@angular/core";
import * as moment from "moment";
@Component(
selector: "app-view",
templateUrl: "./view.component.html",
styleUrls: ["./view.component.css"]
)
export class ViewComponent implements OnInit
fromDate: string;
toDate: string;
item = [
id: 1,
activity_date: "14 November 2018",
];
ngOnInit()
isBetweenDate(date: string)
return moment(date).isBetween(this.fromDate, this.toDate);
It works if I write values in the method by hand, and it only works at the loading of the page.
I was trying to look after the EventEmitter
or the Custom Attributes, but I'm not sure I am moving to the right direction.
javascript angular momentjs
add a comment |
I have two inputs: <input type="date" id="fromDate">
and <input type="date" id="toDate">
, and then a *ngFor
loop iterating through a list of items. All of these items have a property activity_date
.
I want to be able to only show the components having their activity_date
property between the dates of fromDate
and toDate
. For this, I am using MomentJS, more precisely the function moment(activity_date).isBetween(fromDate, toDate)
.
The problem here is I want to assign the result of the previous method to a [hidden]
attribute so if an input
is changed, the [hidden]
property will be updated.
But here's the catch. How can I do to show / hide the components whenever the inputs
are changed ?
Here's what I've tried so far:
view.component.html
<app-events
type="calendar-item"
[hidden]="moment(item.activity_date).isBetween(this.fromDate, this.toDate);"
[data]="item"
></app-events>
view.component.ts
import Component, OnInit from "@angular/core";
import * as moment from "moment";
@Component(
selector: "app-view",
templateUrl: "./view.component.html",
styleUrls: ["./view.component.css"]
)
export class ViewComponent implements OnInit
fromDate: string;
toDate: string;
item = [
id: 1,
activity_date: "14 November 2018",
];
ngOnInit()
isBetweenDate(date: string)
return moment(date).isBetween(this.fromDate, this.toDate);
It works if I write values in the method by hand, and it only works at the loading of the page.
I was trying to look after the EventEmitter
or the Custom Attributes, but I'm not sure I am moving to the right direction.
javascript angular momentjs
I have two inputs: <input type="date" id="fromDate">
and <input type="date" id="toDate">
, and then a *ngFor
loop iterating through a list of items. All of these items have a property activity_date
.
I want to be able to only show the components having their activity_date
property between the dates of fromDate
and toDate
. For this, I am using MomentJS, more precisely the function moment(activity_date).isBetween(fromDate, toDate)
.
The problem here is I want to assign the result of the previous method to a [hidden]
attribute so if an input
is changed, the [hidden]
property will be updated.
But here's the catch. How can I do to show / hide the components whenever the inputs
are changed ?
Here's what I've tried so far:
view.component.html
<app-events
type="calendar-item"
[hidden]="moment(item.activity_date).isBetween(this.fromDate, this.toDate);"
[data]="item"
></app-events>
view.component.ts
import Component, OnInit from "@angular/core";
import * as moment from "moment";
@Component(
selector: "app-view",
templateUrl: "./view.component.html",
styleUrls: ["./view.component.css"]
)
export class ViewComponent implements OnInit
fromDate: string;
toDate: string;
item = [
id: 1,
activity_date: "14 November 2018",
];
ngOnInit()
isBetweenDate(date: string)
return moment(date).isBetween(this.fromDate, this.toDate);
It works if I write values in the method by hand, and it only works at the loading of the page.
I was trying to look after the EventEmitter
or the Custom Attributes, but I'm not sure I am moving to the right direction.
javascript angular momentjs
javascript angular momentjs
asked Nov 14 '18 at 13:04
PrototypePrototype
52110
52110
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I think you have done almost right. You made
isBetweenDate
function but don't use it.
I have created an example for you. It is same as your one, but not exact one. It compares the date with fromDate
and toDate
. So here, you can change dates and you will get an instant output based on the changed dates.
Here is the link:
StackBlitz Link: https://stackblitz.com/edit/angular-48bxrq
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%2f53300925%2fdynamically-show-hide-a-component-if-its-date-is-not-between-2-other-dates%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think you have done almost right. You made
isBetweenDate
function but don't use it.
I have created an example for you. It is same as your one, but not exact one. It compares the date with fromDate
and toDate
. So here, you can change dates and you will get an instant output based on the changed dates.
Here is the link:
StackBlitz Link: https://stackblitz.com/edit/angular-48bxrq
add a comment |
I think you have done almost right. You made
isBetweenDate
function but don't use it.
I have created an example for you. It is same as your one, but not exact one. It compares the date with fromDate
and toDate
. So here, you can change dates and you will get an instant output based on the changed dates.
Here is the link:
StackBlitz Link: https://stackblitz.com/edit/angular-48bxrq
add a comment |
I think you have done almost right. You made
isBetweenDate
function but don't use it.
I have created an example for you. It is same as your one, but not exact one. It compares the date with fromDate
and toDate
. So here, you can change dates and you will get an instant output based on the changed dates.
Here is the link:
StackBlitz Link: https://stackblitz.com/edit/angular-48bxrq
I think you have done almost right. You made
isBetweenDate
function but don't use it.
I have created an example for you. It is same as your one, but not exact one. It compares the date with fromDate
and toDate
. So here, you can change dates and you will get an instant output based on the changed dates.
Here is the link:
StackBlitz Link: https://stackblitz.com/edit/angular-48bxrq
answered Nov 14 '18 at 13:33
Surjeet BhadauriyaSurjeet Bhadauriya
2,00211326
2,00211326
add a comment |
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.
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%2f53300925%2fdynamically-show-hide-a-component-if-its-date-is-not-between-2-other-dates%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