How to convert the Jquery Implemenation to angular 6











up vote
0
down vote

favorite












I have a using https://github.com/nekken/ng2-fullcalendar/ below library for my calander, But there have limited options in this library, so i have used full calender api for extend to fullfill business requriements.



So here is the function Viewrender implementation function to disable previous and next months buttons when crossed future one months and previous one month.



Eg)button should be disable when current month is Nov 2018 - if user clicks on JAn 2019 next button should disable and user choose Sep 2018 previous button should disable.



I have written a logic in jquery inside angualr function , anyone convert this into angular 6 way.



onViewRender(view, element) {
// alert(view.intervalStart);
// alert(view.intervalEnd);
// alert(view.start);
// alert(view.end);
// alert(view.title);
// console.log(view.intervalStart);
// console.log(view.intervalEnd);
var now = new Date();
var end = new Date();
end.setMonth(now.getMonth() + 1);

console.log( view.start.format('MM'));//11
console.log(view.start.format('YYYY'));//2018

var cal_date_string = view.start.format('MM')+'/'+view.start.format('YYYY');
var cur_date_string = now.getMonth()+'/'+now.getFullYear();
var end_date_string = end.getMonth()+'/'+end.getFullYear();

if(cal_date_string == cur_date_string) { jQuery('.fc-prev-button').addClass("fc-state-disabled"); }
else { jQuery('.fc-prev-button').removeClass("fc-state-disabled"); }

if(end_date_string == cal_date_string) { jQuery('.fc-next-button').addClass("fc-state-disabled"); }
else { jQuery('.fc-next-button').removeClass("fc-state-disabled"); }
}


Stackblitz Demo:
demo










share|improve this question




























    up vote
    0
    down vote

    favorite












    I have a using https://github.com/nekken/ng2-fullcalendar/ below library for my calander, But there have limited options in this library, so i have used full calender api for extend to fullfill business requriements.



    So here is the function Viewrender implementation function to disable previous and next months buttons when crossed future one months and previous one month.



    Eg)button should be disable when current month is Nov 2018 - if user clicks on JAn 2019 next button should disable and user choose Sep 2018 previous button should disable.



    I have written a logic in jquery inside angualr function , anyone convert this into angular 6 way.



    onViewRender(view, element) {
    // alert(view.intervalStart);
    // alert(view.intervalEnd);
    // alert(view.start);
    // alert(view.end);
    // alert(view.title);
    // console.log(view.intervalStart);
    // console.log(view.intervalEnd);
    var now = new Date();
    var end = new Date();
    end.setMonth(now.getMonth() + 1);

    console.log( view.start.format('MM'));//11
    console.log(view.start.format('YYYY'));//2018

    var cal_date_string = view.start.format('MM')+'/'+view.start.format('YYYY');
    var cur_date_string = now.getMonth()+'/'+now.getFullYear();
    var end_date_string = end.getMonth()+'/'+end.getFullYear();

    if(cal_date_string == cur_date_string) { jQuery('.fc-prev-button').addClass("fc-state-disabled"); }
    else { jQuery('.fc-prev-button').removeClass("fc-state-disabled"); }

    if(end_date_string == cal_date_string) { jQuery('.fc-next-button').addClass("fc-state-disabled"); }
    else { jQuery('.fc-next-button').removeClass("fc-state-disabled"); }
    }


    Stackblitz Demo:
    demo










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have a using https://github.com/nekken/ng2-fullcalendar/ below library for my calander, But there have limited options in this library, so i have used full calender api for extend to fullfill business requriements.



      So here is the function Viewrender implementation function to disable previous and next months buttons when crossed future one months and previous one month.



      Eg)button should be disable when current month is Nov 2018 - if user clicks on JAn 2019 next button should disable and user choose Sep 2018 previous button should disable.



      I have written a logic in jquery inside angualr function , anyone convert this into angular 6 way.



      onViewRender(view, element) {
      // alert(view.intervalStart);
      // alert(view.intervalEnd);
      // alert(view.start);
      // alert(view.end);
      // alert(view.title);
      // console.log(view.intervalStart);
      // console.log(view.intervalEnd);
      var now = new Date();
      var end = new Date();
      end.setMonth(now.getMonth() + 1);

      console.log( view.start.format('MM'));//11
      console.log(view.start.format('YYYY'));//2018

      var cal_date_string = view.start.format('MM')+'/'+view.start.format('YYYY');
      var cur_date_string = now.getMonth()+'/'+now.getFullYear();
      var end_date_string = end.getMonth()+'/'+end.getFullYear();

      if(cal_date_string == cur_date_string) { jQuery('.fc-prev-button').addClass("fc-state-disabled"); }
      else { jQuery('.fc-prev-button').removeClass("fc-state-disabled"); }

      if(end_date_string == cal_date_string) { jQuery('.fc-next-button').addClass("fc-state-disabled"); }
      else { jQuery('.fc-next-button').removeClass("fc-state-disabled"); }
      }


      Stackblitz Demo:
      demo










      share|improve this question















      I have a using https://github.com/nekken/ng2-fullcalendar/ below library for my calander, But there have limited options in this library, so i have used full calender api for extend to fullfill business requriements.



      So here is the function Viewrender implementation function to disable previous and next months buttons when crossed future one months and previous one month.



      Eg)button should be disable when current month is Nov 2018 - if user clicks on JAn 2019 next button should disable and user choose Sep 2018 previous button should disable.



      I have written a logic in jquery inside angualr function , anyone convert this into angular 6 way.



      onViewRender(view, element) {
      // alert(view.intervalStart);
      // alert(view.intervalEnd);
      // alert(view.start);
      // alert(view.end);
      // alert(view.title);
      // console.log(view.intervalStart);
      // console.log(view.intervalEnd);
      var now = new Date();
      var end = new Date();
      end.setMonth(now.getMonth() + 1);

      console.log( view.start.format('MM'));//11
      console.log(view.start.format('YYYY'));//2018

      var cal_date_string = view.start.format('MM')+'/'+view.start.format('YYYY');
      var cur_date_string = now.getMonth()+'/'+now.getFullYear();
      var end_date_string = end.getMonth()+'/'+end.getFullYear();

      if(cal_date_string == cur_date_string) { jQuery('.fc-prev-button').addClass("fc-state-disabled"); }
      else { jQuery('.fc-prev-button').removeClass("fc-state-disabled"); }

      if(end_date_string == cal_date_string) { jQuery('.fc-next-button').addClass("fc-state-disabled"); }
      else { jQuery('.fc-next-button').removeClass("fc-state-disabled"); }
      }


      Stackblitz Demo:
      demo







      angular fullcalendar angular6 angular-calendar






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 13:38

























      asked Nov 10 at 13:32









      Mohamed Sahir

      55441226




      55441226
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          The easiest way is to use NgClass.



          You create a boolean inside your controller ts code isPrevButtonEnabled and isNextButtonEnabled (class members).



          In your component, you put inside your .fc-prev-button element:



          [ngClass]="{ 'fc-state-disabled': !isPrevButtonEnabled }"


          same thing for your Next button.



          In your ts code, you simply use:



          isPrevButtonEnabled = cal_date_string !== cur_date_string;


          And same thing for NextButton.



          Edit:



          If you can't modify the component code, just use the following to retrieve the DOM element: document.getElementsByClassName("fc-prev-button");.



          But beware, it might be false if the elements are not yet created in the DOM. Use in OnAfterViewInit and you should be fine.






          share|improve this answer























          • can you able to do it in the demo file, because the button builtin there framework.stackblitz.com/edit/github-inz3zg-gfbsdz?file=src/app/…
            – Mohamed Sahir
            Nov 10 at 13:45










          • Edited my answer
            – Mic
            Nov 10 at 14:01











          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%2f53239471%2fhow-to-convert-the-jquery-implemenation-to-angular-6%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








          up vote
          0
          down vote













          The easiest way is to use NgClass.



          You create a boolean inside your controller ts code isPrevButtonEnabled and isNextButtonEnabled (class members).



          In your component, you put inside your .fc-prev-button element:



          [ngClass]="{ 'fc-state-disabled': !isPrevButtonEnabled }"


          same thing for your Next button.



          In your ts code, you simply use:



          isPrevButtonEnabled = cal_date_string !== cur_date_string;


          And same thing for NextButton.



          Edit:



          If you can't modify the component code, just use the following to retrieve the DOM element: document.getElementsByClassName("fc-prev-button");.



          But beware, it might be false if the elements are not yet created in the DOM. Use in OnAfterViewInit and you should be fine.






          share|improve this answer























          • can you able to do it in the demo file, because the button builtin there framework.stackblitz.com/edit/github-inz3zg-gfbsdz?file=src/app/…
            – Mohamed Sahir
            Nov 10 at 13:45










          • Edited my answer
            – Mic
            Nov 10 at 14:01















          up vote
          0
          down vote













          The easiest way is to use NgClass.



          You create a boolean inside your controller ts code isPrevButtonEnabled and isNextButtonEnabled (class members).



          In your component, you put inside your .fc-prev-button element:



          [ngClass]="{ 'fc-state-disabled': !isPrevButtonEnabled }"


          same thing for your Next button.



          In your ts code, you simply use:



          isPrevButtonEnabled = cal_date_string !== cur_date_string;


          And same thing for NextButton.



          Edit:



          If you can't modify the component code, just use the following to retrieve the DOM element: document.getElementsByClassName("fc-prev-button");.



          But beware, it might be false if the elements are not yet created in the DOM. Use in OnAfterViewInit and you should be fine.






          share|improve this answer























          • can you able to do it in the demo file, because the button builtin there framework.stackblitz.com/edit/github-inz3zg-gfbsdz?file=src/app/…
            – Mohamed Sahir
            Nov 10 at 13:45










          • Edited my answer
            – Mic
            Nov 10 at 14:01













          up vote
          0
          down vote










          up vote
          0
          down vote









          The easiest way is to use NgClass.



          You create a boolean inside your controller ts code isPrevButtonEnabled and isNextButtonEnabled (class members).



          In your component, you put inside your .fc-prev-button element:



          [ngClass]="{ 'fc-state-disabled': !isPrevButtonEnabled }"


          same thing for your Next button.



          In your ts code, you simply use:



          isPrevButtonEnabled = cal_date_string !== cur_date_string;


          And same thing for NextButton.



          Edit:



          If you can't modify the component code, just use the following to retrieve the DOM element: document.getElementsByClassName("fc-prev-button");.



          But beware, it might be false if the elements are not yet created in the DOM. Use in OnAfterViewInit and you should be fine.






          share|improve this answer














          The easiest way is to use NgClass.



          You create a boolean inside your controller ts code isPrevButtonEnabled and isNextButtonEnabled (class members).



          In your component, you put inside your .fc-prev-button element:



          [ngClass]="{ 'fc-state-disabled': !isPrevButtonEnabled }"


          same thing for your Next button.



          In your ts code, you simply use:



          isPrevButtonEnabled = cal_date_string !== cur_date_string;


          And same thing for NextButton.



          Edit:



          If you can't modify the component code, just use the following to retrieve the DOM element: document.getElementsByClassName("fc-prev-button");.



          But beware, it might be false if the elements are not yet created in the DOM. Use in OnAfterViewInit and you should be fine.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 10 at 14:01

























          answered Nov 10 at 13:41









          Mic

          1,92111431




          1,92111431












          • can you able to do it in the demo file, because the button builtin there framework.stackblitz.com/edit/github-inz3zg-gfbsdz?file=src/app/…
            – Mohamed Sahir
            Nov 10 at 13:45










          • Edited my answer
            – Mic
            Nov 10 at 14:01


















          • can you able to do it in the demo file, because the button builtin there framework.stackblitz.com/edit/github-inz3zg-gfbsdz?file=src/app/…
            – Mohamed Sahir
            Nov 10 at 13:45










          • Edited my answer
            – Mic
            Nov 10 at 14:01
















          can you able to do it in the demo file, because the button builtin there framework.stackblitz.com/edit/github-inz3zg-gfbsdz?file=src/app/…
          – Mohamed Sahir
          Nov 10 at 13:45




          can you able to do it in the demo file, because the button builtin there framework.stackblitz.com/edit/github-inz3zg-gfbsdz?file=src/app/…
          – Mohamed Sahir
          Nov 10 at 13:45












          Edited my answer
          – Mic
          Nov 10 at 14:01




          Edited my answer
          – Mic
          Nov 10 at 14:01


















          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.





          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239471%2fhow-to-convert-the-jquery-implemenation-to-angular-6%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







          這個網誌中的熱門文章

          Tangent Lines Diagram Along Smooth Curve

          Yusuf al-Mu'taman ibn Hud

          Zucchini