Angular 2 *ngIf statement with multiple values
Maybe an outdated question but I cant get it to work.
I have an *ngIF statement and i want to use multiple conditions like this:
*ngIf="expression && prototype?.valueType === 'Integer' && 'String'"
How do I set this *ngIf with multiple conditions?
typescript
add a comment |
Maybe an outdated question but I cant get it to work.
I have an *ngIF statement and i want to use multiple conditions like this:
*ngIf="expression && prototype?.valueType === 'Integer' && 'String'"
How do I set this *ngIf with multiple conditions?
typescript
add a comment |
Maybe an outdated question but I cant get it to work.
I have an *ngIF statement and i want to use multiple conditions like this:
*ngIf="expression && prototype?.valueType === 'Integer' && 'String'"
How do I set this *ngIf with multiple conditions?
typescript
Maybe an outdated question but I cant get it to work.
I have an *ngIF statement and i want to use multiple conditions like this:
*ngIf="expression && prototype?.valueType === 'Integer' && 'String'"
How do I set this *ngIf with multiple conditions?
typescript
typescript
asked Apr 19 '16 at 15:17
SireiniSireini
1,41252852
1,41252852
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
This usually works fine.
The expression
*ngIf="expression && prototype?.valueType === 'Integer' && 'String'"
seems a bit off.
Perhaps you want something like
*ngIf="expression && (prototype?.valueType === 'Integer' || prototype?.valueType === 'String'")
Trying to check like*ngIf="projectId!==undefined && projectId!==null && projectId!==''"doesn't throw any errors but doesnt seem to work too. Can't seem to figure it out
– Wouter Vanherck
Apr 20 '17 at 8:15
1
Please create a Plunker that allows to reproduce. Shouldn't*ngIf="projectId"be sufficient?
– Günter Zöchbauer
Apr 20 '17 at 8:17
Yes, it should be enough. The above was a desperate test. Yet it doesn't work like expected. I'm not able to create a plunker because that would ask me to create allot of files like services and models (I don't know how to setup the plunker without them) but I appreciate the quick response.
– Wouter Vanherck
Apr 20 '17 at 8:33
I'm not sure what you mean with a lot of files like ... Plunker provides a ready-to-use Angular2 template. If it's about your custom code, I doubt it's related to the*ngIfexpression when you think you need a lot of services and models to reproduce.
– Günter Zöchbauer
Apr 20 '17 at 8:35
That's because you didn't start with the Angular template provided by Plunker.
– Günter Zöchbauer
Apr 20 '17 at 8:54
add a comment |
I agree with what Gunter Zochbauer said..but if you are to supposed to check both conditions then following is most efficient way. Just replacing '||' , and including '&&', because '||' checks "Or" condition which is true if either of check on left or right side is true, and "&&" checks and condition, which means right and left side of that and clause should be true to meet requirement. In your function it will look like -
*ngIf="expression && (prototype?.valueType==='Integer' && prototype?.valueType=== 'String'")
if you want to comment about other answers, you can first earn rep by contributing in the site. this more likely to be a comment on the other post.
– Vikrant
Nov 27 '18 at 7: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%2f36722605%2fangular-2-ngif-statement-with-multiple-values%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
This usually works fine.
The expression
*ngIf="expression && prototype?.valueType === 'Integer' && 'String'"
seems a bit off.
Perhaps you want something like
*ngIf="expression && (prototype?.valueType === 'Integer' || prototype?.valueType === 'String'")
Trying to check like*ngIf="projectId!==undefined && projectId!==null && projectId!==''"doesn't throw any errors but doesnt seem to work too. Can't seem to figure it out
– Wouter Vanherck
Apr 20 '17 at 8:15
1
Please create a Plunker that allows to reproduce. Shouldn't*ngIf="projectId"be sufficient?
– Günter Zöchbauer
Apr 20 '17 at 8:17
Yes, it should be enough. The above was a desperate test. Yet it doesn't work like expected. I'm not able to create a plunker because that would ask me to create allot of files like services and models (I don't know how to setup the plunker without them) but I appreciate the quick response.
– Wouter Vanherck
Apr 20 '17 at 8:33
I'm not sure what you mean with a lot of files like ... Plunker provides a ready-to-use Angular2 template. If it's about your custom code, I doubt it's related to the*ngIfexpression when you think you need a lot of services and models to reproduce.
– Günter Zöchbauer
Apr 20 '17 at 8:35
That's because you didn't start with the Angular template provided by Plunker.
– Günter Zöchbauer
Apr 20 '17 at 8:54
add a comment |
This usually works fine.
The expression
*ngIf="expression && prototype?.valueType === 'Integer' && 'String'"
seems a bit off.
Perhaps you want something like
*ngIf="expression && (prototype?.valueType === 'Integer' || prototype?.valueType === 'String'")
Trying to check like*ngIf="projectId!==undefined && projectId!==null && projectId!==''"doesn't throw any errors but doesnt seem to work too. Can't seem to figure it out
– Wouter Vanherck
Apr 20 '17 at 8:15
1
Please create a Plunker that allows to reproduce. Shouldn't*ngIf="projectId"be sufficient?
– Günter Zöchbauer
Apr 20 '17 at 8:17
Yes, it should be enough. The above was a desperate test. Yet it doesn't work like expected. I'm not able to create a plunker because that would ask me to create allot of files like services and models (I don't know how to setup the plunker without them) but I appreciate the quick response.
– Wouter Vanherck
Apr 20 '17 at 8:33
I'm not sure what you mean with a lot of files like ... Plunker provides a ready-to-use Angular2 template. If it's about your custom code, I doubt it's related to the*ngIfexpression when you think you need a lot of services and models to reproduce.
– Günter Zöchbauer
Apr 20 '17 at 8:35
That's because you didn't start with the Angular template provided by Plunker.
– Günter Zöchbauer
Apr 20 '17 at 8:54
add a comment |
This usually works fine.
The expression
*ngIf="expression && prototype?.valueType === 'Integer' && 'String'"
seems a bit off.
Perhaps you want something like
*ngIf="expression && (prototype?.valueType === 'Integer' || prototype?.valueType === 'String'")
This usually works fine.
The expression
*ngIf="expression && prototype?.valueType === 'Integer' && 'String'"
seems a bit off.
Perhaps you want something like
*ngIf="expression && (prototype?.valueType === 'Integer' || prototype?.valueType === 'String'")
answered Apr 19 '16 at 15:20
Günter ZöchbauerGünter Zöchbauer
327k69979919
327k69979919
Trying to check like*ngIf="projectId!==undefined && projectId!==null && projectId!==''"doesn't throw any errors but doesnt seem to work too. Can't seem to figure it out
– Wouter Vanherck
Apr 20 '17 at 8:15
1
Please create a Plunker that allows to reproduce. Shouldn't*ngIf="projectId"be sufficient?
– Günter Zöchbauer
Apr 20 '17 at 8:17
Yes, it should be enough. The above was a desperate test. Yet it doesn't work like expected. I'm not able to create a plunker because that would ask me to create allot of files like services and models (I don't know how to setup the plunker without them) but I appreciate the quick response.
– Wouter Vanherck
Apr 20 '17 at 8:33
I'm not sure what you mean with a lot of files like ... Plunker provides a ready-to-use Angular2 template. If it's about your custom code, I doubt it's related to the*ngIfexpression when you think you need a lot of services and models to reproduce.
– Günter Zöchbauer
Apr 20 '17 at 8:35
That's because you didn't start with the Angular template provided by Plunker.
– Günter Zöchbauer
Apr 20 '17 at 8:54
add a comment |
Trying to check like*ngIf="projectId!==undefined && projectId!==null && projectId!==''"doesn't throw any errors but doesnt seem to work too. Can't seem to figure it out
– Wouter Vanherck
Apr 20 '17 at 8:15
1
Please create a Plunker that allows to reproduce. Shouldn't*ngIf="projectId"be sufficient?
– Günter Zöchbauer
Apr 20 '17 at 8:17
Yes, it should be enough. The above was a desperate test. Yet it doesn't work like expected. I'm not able to create a plunker because that would ask me to create allot of files like services and models (I don't know how to setup the plunker without them) but I appreciate the quick response.
– Wouter Vanherck
Apr 20 '17 at 8:33
I'm not sure what you mean with a lot of files like ... Plunker provides a ready-to-use Angular2 template. If it's about your custom code, I doubt it's related to the*ngIfexpression when you think you need a lot of services and models to reproduce.
– Günter Zöchbauer
Apr 20 '17 at 8:35
That's because you didn't start with the Angular template provided by Plunker.
– Günter Zöchbauer
Apr 20 '17 at 8:54
Trying to check like
*ngIf="projectId!==undefined && projectId!==null && projectId!==''" doesn't throw any errors but doesnt seem to work too. Can't seem to figure it out– Wouter Vanherck
Apr 20 '17 at 8:15
Trying to check like
*ngIf="projectId!==undefined && projectId!==null && projectId!==''" doesn't throw any errors but doesnt seem to work too. Can't seem to figure it out– Wouter Vanherck
Apr 20 '17 at 8:15
1
1
Please create a Plunker that allows to reproduce. Shouldn't
*ngIf="projectId" be sufficient?– Günter Zöchbauer
Apr 20 '17 at 8:17
Please create a Plunker that allows to reproduce. Shouldn't
*ngIf="projectId" be sufficient?– Günter Zöchbauer
Apr 20 '17 at 8:17
Yes, it should be enough. The above was a desperate test. Yet it doesn't work like expected. I'm not able to create a plunker because that would ask me to create allot of files like services and models (I don't know how to setup the plunker without them) but I appreciate the quick response.
– Wouter Vanherck
Apr 20 '17 at 8:33
Yes, it should be enough. The above was a desperate test. Yet it doesn't work like expected. I'm not able to create a plunker because that would ask me to create allot of files like services and models (I don't know how to setup the plunker without them) but I appreciate the quick response.
– Wouter Vanherck
Apr 20 '17 at 8:33
I'm not sure what you mean with a lot of files like ... Plunker provides a ready-to-use Angular2 template. If it's about your custom code, I doubt it's related to the
*ngIf expression when you think you need a lot of services and models to reproduce.– Günter Zöchbauer
Apr 20 '17 at 8:35
I'm not sure what you mean with a lot of files like ... Plunker provides a ready-to-use Angular2 template. If it's about your custom code, I doubt it's related to the
*ngIf expression when you think you need a lot of services and models to reproduce.– Günter Zöchbauer
Apr 20 '17 at 8:35
That's because you didn't start with the Angular template provided by Plunker.
– Günter Zöchbauer
Apr 20 '17 at 8:54
That's because you didn't start with the Angular template provided by Plunker.
– Günter Zöchbauer
Apr 20 '17 at 8:54
add a comment |
I agree with what Gunter Zochbauer said..but if you are to supposed to check both conditions then following is most efficient way. Just replacing '||' , and including '&&', because '||' checks "Or" condition which is true if either of check on left or right side is true, and "&&" checks and condition, which means right and left side of that and clause should be true to meet requirement. In your function it will look like -
*ngIf="expression && (prototype?.valueType==='Integer' && prototype?.valueType=== 'String'")
if you want to comment about other answers, you can first earn rep by contributing in the site. this more likely to be a comment on the other post.
– Vikrant
Nov 27 '18 at 7:59
add a comment |
I agree with what Gunter Zochbauer said..but if you are to supposed to check both conditions then following is most efficient way. Just replacing '||' , and including '&&', because '||' checks "Or" condition which is true if either of check on left or right side is true, and "&&" checks and condition, which means right and left side of that and clause should be true to meet requirement. In your function it will look like -
*ngIf="expression && (prototype?.valueType==='Integer' && prototype?.valueType=== 'String'")
if you want to comment about other answers, you can first earn rep by contributing in the site. this more likely to be a comment on the other post.
– Vikrant
Nov 27 '18 at 7:59
add a comment |
I agree with what Gunter Zochbauer said..but if you are to supposed to check both conditions then following is most efficient way. Just replacing '||' , and including '&&', because '||' checks "Or" condition which is true if either of check on left or right side is true, and "&&" checks and condition, which means right and left side of that and clause should be true to meet requirement. In your function it will look like -
*ngIf="expression && (prototype?.valueType==='Integer' && prototype?.valueType=== 'String'")
I agree with what Gunter Zochbauer said..but if you are to supposed to check both conditions then following is most efficient way. Just replacing '||' , and including '&&', because '||' checks "Or" condition which is true if either of check on left or right side is true, and "&&" checks and condition, which means right and left side of that and clause should be true to meet requirement. In your function it will look like -
*ngIf="expression && (prototype?.valueType==='Integer' && prototype?.valueType=== 'String'")
answered Nov 27 '18 at 7:26
surendrapandaysurendrapanday
1067
1067
if you want to comment about other answers, you can first earn rep by contributing in the site. this more likely to be a comment on the other post.
– Vikrant
Nov 27 '18 at 7:59
add a comment |
if you want to comment about other answers, you can first earn rep by contributing in the site. this more likely to be a comment on the other post.
– Vikrant
Nov 27 '18 at 7:59
if you want to comment about other answers, you can first earn rep by contributing in the site. this more likely to be a comment on the other post.
– Vikrant
Nov 27 '18 at 7:59
if you want to comment about other answers, you can first earn rep by contributing in the site. this more likely to be a comment on the other post.
– Vikrant
Nov 27 '18 at 7: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.
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%2f36722605%2fangular-2-ngif-statement-with-multiple-values%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