Angular 2 *ngIf statement with multiple values












33















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?










share|improve this question



























    33















    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?










    share|improve this question

























      33












      33








      33


      9






      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?










      share|improve this question














      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 angular






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Apr 19 '16 at 15:17









      SireiniSireini

      1,41252852




      1,41252852
























          2 Answers
          2






          active

          oldest

          votes


















          49














          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'")





          share|improve this answer
























          • 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 *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



















          0














          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'")






          share|improve this answer
























          • 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











          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
          });


          }
          });














          draft saved

          draft discarded


















          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









          49














          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'")





          share|improve this answer
























          • 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 *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
















          49














          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'")





          share|improve this answer
























          • 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 *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














          49












          49








          49







          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'")





          share|improve this answer













          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'")






          share|improve this answer












          share|improve this answer



          share|improve this answer










          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 *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



















          • 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 *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

















          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













          0














          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'")






          share|improve this answer
























          • 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
















          0














          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'")






          share|improve this answer
























          • 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














          0












          0








          0







          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'")






          share|improve this answer













          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'")







          share|improve this answer












          share|improve this answer



          share|improve this answer










          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



















          • 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


















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Lallio

          Futebolista

          Jornalista