PrimeNG TypeError “this._activeIndex.includes” is not a function










0














I have a component in which I use an accordion.I want to have multiple tabs enabled and a custom activeIndex.
Here is my code :



<p-accordion [activeIndex]="index" [multiple]="true">
<p-accordionTab header="1st tab">
1st tab content
</p-accordionTab>
<p-accordionTab header="2nd tab">
2nd tab content
</p-accordionTab>
</p-accordion>


Here is my component class



@Component(
selector: 'app-panel',
templateUrl: './panel.component.html',
styleUrls: ['./panel.component.css']
)
export class PanelComponent implements OnInit

index:number = 1;
constructor()



ngOnInit()
//this.index = 0;





The problem appears If I want to include both [activeIndex] and [multiple].Any ideas why this is happening?



I use PrimeNG 7 and angular 7










share|improve this question























  • Docs says - "Index of the active tab or an array of indexes to change selected tab programmatically.", try array of indices, also note that the error suggests an array.
    – sabithpocker
    Nov 12 '18 at 16:43















0














I have a component in which I use an accordion.I want to have multiple tabs enabled and a custom activeIndex.
Here is my code :



<p-accordion [activeIndex]="index" [multiple]="true">
<p-accordionTab header="1st tab">
1st tab content
</p-accordionTab>
<p-accordionTab header="2nd tab">
2nd tab content
</p-accordionTab>
</p-accordion>


Here is my component class



@Component(
selector: 'app-panel',
templateUrl: './panel.component.html',
styleUrls: ['./panel.component.css']
)
export class PanelComponent implements OnInit

index:number = 1;
constructor()



ngOnInit()
//this.index = 0;





The problem appears If I want to include both [activeIndex] and [multiple].Any ideas why this is happening?



I use PrimeNG 7 and angular 7










share|improve this question























  • Docs says - "Index of the active tab or an array of indexes to change selected tab programmatically.", try array of indices, also note that the error suggests an array.
    – sabithpocker
    Nov 12 '18 at 16:43













0












0








0







I have a component in which I use an accordion.I want to have multiple tabs enabled and a custom activeIndex.
Here is my code :



<p-accordion [activeIndex]="index" [multiple]="true">
<p-accordionTab header="1st tab">
1st tab content
</p-accordionTab>
<p-accordionTab header="2nd tab">
2nd tab content
</p-accordionTab>
</p-accordion>


Here is my component class



@Component(
selector: 'app-panel',
templateUrl: './panel.component.html',
styleUrls: ['./panel.component.css']
)
export class PanelComponent implements OnInit

index:number = 1;
constructor()



ngOnInit()
//this.index = 0;





The problem appears If I want to include both [activeIndex] and [multiple].Any ideas why this is happening?



I use PrimeNG 7 and angular 7










share|improve this question















I have a component in which I use an accordion.I want to have multiple tabs enabled and a custom activeIndex.
Here is my code :



<p-accordion [activeIndex]="index" [multiple]="true">
<p-accordionTab header="1st tab">
1st tab content
</p-accordionTab>
<p-accordionTab header="2nd tab">
2nd tab content
</p-accordionTab>
</p-accordion>


Here is my component class



@Component(
selector: 'app-panel',
templateUrl: './panel.component.html',
styleUrls: ['./panel.component.css']
)
export class PanelComponent implements OnInit

index:number = 1;
constructor()



ngOnInit()
//this.index = 0;





The problem appears If I want to include both [activeIndex] and [multiple].Any ideas why this is happening?



I use PrimeNG 7 and angular 7







angular primeng angular7






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 10:52









Goncalo Peres

1,3261318




1,3261318










asked Nov 12 '18 at 16:17









Manos Kounelakis

754826




754826











  • Docs says - "Index of the active tab or an array of indexes to change selected tab programmatically.", try array of indices, also note that the error suggests an array.
    – sabithpocker
    Nov 12 '18 at 16:43
















  • Docs says - "Index of the active tab or an array of indexes to change selected tab programmatically.", try array of indices, also note that the error suggests an array.
    – sabithpocker
    Nov 12 '18 at 16:43















Docs says - "Index of the active tab or an array of indexes to change selected tab programmatically.", try array of indices, also note that the error suggests an array.
– sabithpocker
Nov 12 '18 at 16:43




Docs says - "Index of the active tab or an array of indexes to change selected tab programmatically.", try array of indices, also note that the error suggests an array.
– sabithpocker
Nov 12 '18 at 16:43












2 Answers
2






active

oldest

votes


















1














You can't be using both. It's either one or the other.



multiple: When enabled, multiple tabs can be activated at the same time.



activeIndex: Index of the active tab or an array of indexes to change selected tab programmatically.



Because of the way they work, they will be contradicting each other. One is to have several open, the other one is to have just one open.



https://www.primefaces.org/primeng/#/accordion



For example:



Imagine you have a function that says openDoor() and one that it's called closedDoor() if you use them at the SAME TIME they will contradict to each other.



This is what you need:



<p-accordion [multiple]="true" >
<p-accordionTab header="Header 1" [selected]="true">
Content 1
</p-accordionTab>
<p-accordionTab header="Header 2">
Content 2
</p-accordionTab>
<p-accordionTab header="Header 3">
Content 3
</p-accordionTab>
</p-accordion>





share|improve this answer






















  • But what happens If I want to have multiple tabs and the first one selected by default?
    – Manos Kounelakis
    Nov 12 '18 at 16:27










  • Also notice that If I bind [multiple] to a boolean variable inside my component class the error goes away
    – Manos Kounelakis
    Nov 12 '18 at 16:28










  • the activeIndex is not to have one accordion open by default. It's to open it programatically. That's why they put the arrows in the example. You have to use the [selected]="true" in the tab you want to have open by default @ManosKounelakis
    – TAMO Studio
    Nov 12 '18 at 16:36











  • @ManosKounelakis take a look to my updated answer
    – TAMO Studio
    Nov 12 '18 at 16:37






  • 1




    Accepted and upvoted.Took me some hours for a simillar project that would throw me a strange error.Now I got it
    – Manos Kounelakis
    Nov 12 '18 at 16:41


















1














Docs says:




Index of the active tab or an array of indexes to change selected tab
programmatically.




Here is the related code where it sets activeTabs from _activeIndex



 updateSelectionState() 
if (this.tabs && this.tabs.length && this._activeIndex != null)
for (let i = 0; i < this.tabs.length; i++)
let selected = this.multiple ? this._activeIndex.includes(i) : (i === this._activeIndex);
let changed = selected !== this.tabs[i].selected;

if (changed)
this.tabs[i].animating = true;


this.tabs[i].selected = selected;
this.tabs[i].selectedChange.emit(selected);





So, for multiple tabs, you should be using an array of indices, not a number.



@Component(
selector: 'app-panel',
templateUrl: './panel.component.html',
styleUrls: ['./panel.component.css']
)
export class PanelComponent implements OnInit

indices: number = [1, 2];
constructor()



ngOnInit()
//this.index = 0;





If you are wondering, this._activeIndex.includes(i) this is where your error comes from.






share|improve this answer




















    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%2f53266132%2fprimeng-typeerror-this-activeindex-includes-is-not-a-function%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









    1














    You can't be using both. It's either one or the other.



    multiple: When enabled, multiple tabs can be activated at the same time.



    activeIndex: Index of the active tab or an array of indexes to change selected tab programmatically.



    Because of the way they work, they will be contradicting each other. One is to have several open, the other one is to have just one open.



    https://www.primefaces.org/primeng/#/accordion



    For example:



    Imagine you have a function that says openDoor() and one that it's called closedDoor() if you use them at the SAME TIME they will contradict to each other.



    This is what you need:



    <p-accordion [multiple]="true" >
    <p-accordionTab header="Header 1" [selected]="true">
    Content 1
    </p-accordionTab>
    <p-accordionTab header="Header 2">
    Content 2
    </p-accordionTab>
    <p-accordionTab header="Header 3">
    Content 3
    </p-accordionTab>
    </p-accordion>





    share|improve this answer






















    • But what happens If I want to have multiple tabs and the first one selected by default?
      – Manos Kounelakis
      Nov 12 '18 at 16:27










    • Also notice that If I bind [multiple] to a boolean variable inside my component class the error goes away
      – Manos Kounelakis
      Nov 12 '18 at 16:28










    • the activeIndex is not to have one accordion open by default. It's to open it programatically. That's why they put the arrows in the example. You have to use the [selected]="true" in the tab you want to have open by default @ManosKounelakis
      – TAMO Studio
      Nov 12 '18 at 16:36











    • @ManosKounelakis take a look to my updated answer
      – TAMO Studio
      Nov 12 '18 at 16:37






    • 1




      Accepted and upvoted.Took me some hours for a simillar project that would throw me a strange error.Now I got it
      – Manos Kounelakis
      Nov 12 '18 at 16:41















    1














    You can't be using both. It's either one or the other.



    multiple: When enabled, multiple tabs can be activated at the same time.



    activeIndex: Index of the active tab or an array of indexes to change selected tab programmatically.



    Because of the way they work, they will be contradicting each other. One is to have several open, the other one is to have just one open.



    https://www.primefaces.org/primeng/#/accordion



    For example:



    Imagine you have a function that says openDoor() and one that it's called closedDoor() if you use them at the SAME TIME they will contradict to each other.



    This is what you need:



    <p-accordion [multiple]="true" >
    <p-accordionTab header="Header 1" [selected]="true">
    Content 1
    </p-accordionTab>
    <p-accordionTab header="Header 2">
    Content 2
    </p-accordionTab>
    <p-accordionTab header="Header 3">
    Content 3
    </p-accordionTab>
    </p-accordion>





    share|improve this answer






















    • But what happens If I want to have multiple tabs and the first one selected by default?
      – Manos Kounelakis
      Nov 12 '18 at 16:27










    • Also notice that If I bind [multiple] to a boolean variable inside my component class the error goes away
      – Manos Kounelakis
      Nov 12 '18 at 16:28










    • the activeIndex is not to have one accordion open by default. It's to open it programatically. That's why they put the arrows in the example. You have to use the [selected]="true" in the tab you want to have open by default @ManosKounelakis
      – TAMO Studio
      Nov 12 '18 at 16:36











    • @ManosKounelakis take a look to my updated answer
      – TAMO Studio
      Nov 12 '18 at 16:37






    • 1




      Accepted and upvoted.Took me some hours for a simillar project that would throw me a strange error.Now I got it
      – Manos Kounelakis
      Nov 12 '18 at 16:41













    1












    1








    1






    You can't be using both. It's either one or the other.



    multiple: When enabled, multiple tabs can be activated at the same time.



    activeIndex: Index of the active tab or an array of indexes to change selected tab programmatically.



    Because of the way they work, they will be contradicting each other. One is to have several open, the other one is to have just one open.



    https://www.primefaces.org/primeng/#/accordion



    For example:



    Imagine you have a function that says openDoor() and one that it's called closedDoor() if you use them at the SAME TIME they will contradict to each other.



    This is what you need:



    <p-accordion [multiple]="true" >
    <p-accordionTab header="Header 1" [selected]="true">
    Content 1
    </p-accordionTab>
    <p-accordionTab header="Header 2">
    Content 2
    </p-accordionTab>
    <p-accordionTab header="Header 3">
    Content 3
    </p-accordionTab>
    </p-accordion>





    share|improve this answer














    You can't be using both. It's either one or the other.



    multiple: When enabled, multiple tabs can be activated at the same time.



    activeIndex: Index of the active tab or an array of indexes to change selected tab programmatically.



    Because of the way they work, they will be contradicting each other. One is to have several open, the other one is to have just one open.



    https://www.primefaces.org/primeng/#/accordion



    For example:



    Imagine you have a function that says openDoor() and one that it's called closedDoor() if you use them at the SAME TIME they will contradict to each other.



    This is what you need:



    <p-accordion [multiple]="true" >
    <p-accordionTab header="Header 1" [selected]="true">
    Content 1
    </p-accordionTab>
    <p-accordionTab header="Header 2">
    Content 2
    </p-accordionTab>
    <p-accordionTab header="Header 3">
    Content 3
    </p-accordionTab>
    </p-accordion>






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 12 '18 at 16:37

























    answered Nov 12 '18 at 16:24









    TAMO Studio

    1,3631523




    1,3631523











    • But what happens If I want to have multiple tabs and the first one selected by default?
      – Manos Kounelakis
      Nov 12 '18 at 16:27










    • Also notice that If I bind [multiple] to a boolean variable inside my component class the error goes away
      – Manos Kounelakis
      Nov 12 '18 at 16:28










    • the activeIndex is not to have one accordion open by default. It's to open it programatically. That's why they put the arrows in the example. You have to use the [selected]="true" in the tab you want to have open by default @ManosKounelakis
      – TAMO Studio
      Nov 12 '18 at 16:36











    • @ManosKounelakis take a look to my updated answer
      – TAMO Studio
      Nov 12 '18 at 16:37






    • 1




      Accepted and upvoted.Took me some hours for a simillar project that would throw me a strange error.Now I got it
      – Manos Kounelakis
      Nov 12 '18 at 16:41
















    • But what happens If I want to have multiple tabs and the first one selected by default?
      – Manos Kounelakis
      Nov 12 '18 at 16:27










    • Also notice that If I bind [multiple] to a boolean variable inside my component class the error goes away
      – Manos Kounelakis
      Nov 12 '18 at 16:28










    • the activeIndex is not to have one accordion open by default. It's to open it programatically. That's why they put the arrows in the example. You have to use the [selected]="true" in the tab you want to have open by default @ManosKounelakis
      – TAMO Studio
      Nov 12 '18 at 16:36











    • @ManosKounelakis take a look to my updated answer
      – TAMO Studio
      Nov 12 '18 at 16:37






    • 1




      Accepted and upvoted.Took me some hours for a simillar project that would throw me a strange error.Now I got it
      – Manos Kounelakis
      Nov 12 '18 at 16:41















    But what happens If I want to have multiple tabs and the first one selected by default?
    – Manos Kounelakis
    Nov 12 '18 at 16:27




    But what happens If I want to have multiple tabs and the first one selected by default?
    – Manos Kounelakis
    Nov 12 '18 at 16:27












    Also notice that If I bind [multiple] to a boolean variable inside my component class the error goes away
    – Manos Kounelakis
    Nov 12 '18 at 16:28




    Also notice that If I bind [multiple] to a boolean variable inside my component class the error goes away
    – Manos Kounelakis
    Nov 12 '18 at 16:28












    the activeIndex is not to have one accordion open by default. It's to open it programatically. That's why they put the arrows in the example. You have to use the [selected]="true" in the tab you want to have open by default @ManosKounelakis
    – TAMO Studio
    Nov 12 '18 at 16:36





    the activeIndex is not to have one accordion open by default. It's to open it programatically. That's why they put the arrows in the example. You have to use the [selected]="true" in the tab you want to have open by default @ManosKounelakis
    – TAMO Studio
    Nov 12 '18 at 16:36













    @ManosKounelakis take a look to my updated answer
    – TAMO Studio
    Nov 12 '18 at 16:37




    @ManosKounelakis take a look to my updated answer
    – TAMO Studio
    Nov 12 '18 at 16:37




    1




    1




    Accepted and upvoted.Took me some hours for a simillar project that would throw me a strange error.Now I got it
    – Manos Kounelakis
    Nov 12 '18 at 16:41




    Accepted and upvoted.Took me some hours for a simillar project that would throw me a strange error.Now I got it
    – Manos Kounelakis
    Nov 12 '18 at 16:41













    1














    Docs says:




    Index of the active tab or an array of indexes to change selected tab
    programmatically.




    Here is the related code where it sets activeTabs from _activeIndex



     updateSelectionState() 
    if (this.tabs && this.tabs.length && this._activeIndex != null)
    for (let i = 0; i < this.tabs.length; i++)
    let selected = this.multiple ? this._activeIndex.includes(i) : (i === this._activeIndex);
    let changed = selected !== this.tabs[i].selected;

    if (changed)
    this.tabs[i].animating = true;


    this.tabs[i].selected = selected;
    this.tabs[i].selectedChange.emit(selected);





    So, for multiple tabs, you should be using an array of indices, not a number.



    @Component(
    selector: 'app-panel',
    templateUrl: './panel.component.html',
    styleUrls: ['./panel.component.css']
    )
    export class PanelComponent implements OnInit

    indices: number = [1, 2];
    constructor()



    ngOnInit()
    //this.index = 0;





    If you are wondering, this._activeIndex.includes(i) this is where your error comes from.






    share|improve this answer

























      1














      Docs says:




      Index of the active tab or an array of indexes to change selected tab
      programmatically.




      Here is the related code where it sets activeTabs from _activeIndex



       updateSelectionState() 
      if (this.tabs && this.tabs.length && this._activeIndex != null)
      for (let i = 0; i < this.tabs.length; i++)
      let selected = this.multiple ? this._activeIndex.includes(i) : (i === this._activeIndex);
      let changed = selected !== this.tabs[i].selected;

      if (changed)
      this.tabs[i].animating = true;


      this.tabs[i].selected = selected;
      this.tabs[i].selectedChange.emit(selected);





      So, for multiple tabs, you should be using an array of indices, not a number.



      @Component(
      selector: 'app-panel',
      templateUrl: './panel.component.html',
      styleUrls: ['./panel.component.css']
      )
      export class PanelComponent implements OnInit

      indices: number = [1, 2];
      constructor()



      ngOnInit()
      //this.index = 0;





      If you are wondering, this._activeIndex.includes(i) this is where your error comes from.






      share|improve this answer























        1












        1








        1






        Docs says:




        Index of the active tab or an array of indexes to change selected tab
        programmatically.




        Here is the related code where it sets activeTabs from _activeIndex



         updateSelectionState() 
        if (this.tabs && this.tabs.length && this._activeIndex != null)
        for (let i = 0; i < this.tabs.length; i++)
        let selected = this.multiple ? this._activeIndex.includes(i) : (i === this._activeIndex);
        let changed = selected !== this.tabs[i].selected;

        if (changed)
        this.tabs[i].animating = true;


        this.tabs[i].selected = selected;
        this.tabs[i].selectedChange.emit(selected);





        So, for multiple tabs, you should be using an array of indices, not a number.



        @Component(
        selector: 'app-panel',
        templateUrl: './panel.component.html',
        styleUrls: ['./panel.component.css']
        )
        export class PanelComponent implements OnInit

        indices: number = [1, 2];
        constructor()



        ngOnInit()
        //this.index = 0;





        If you are wondering, this._activeIndex.includes(i) this is where your error comes from.






        share|improve this answer












        Docs says:




        Index of the active tab or an array of indexes to change selected tab
        programmatically.




        Here is the related code where it sets activeTabs from _activeIndex



         updateSelectionState() 
        if (this.tabs && this.tabs.length && this._activeIndex != null)
        for (let i = 0; i < this.tabs.length; i++)
        let selected = this.multiple ? this._activeIndex.includes(i) : (i === this._activeIndex);
        let changed = selected !== this.tabs[i].selected;

        if (changed)
        this.tabs[i].animating = true;


        this.tabs[i].selected = selected;
        this.tabs[i].selectedChange.emit(selected);





        So, for multiple tabs, you should be using an array of indices, not a number.



        @Component(
        selector: 'app-panel',
        templateUrl: './panel.component.html',
        styleUrls: ['./panel.component.css']
        )
        export class PanelComponent implements OnInit

        indices: number = [1, 2];
        constructor()



        ngOnInit()
        //this.index = 0;





        If you are wondering, this._activeIndex.includes(i) this is where your error comes from.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 12 '18 at 16:50









        sabithpocker

        11.3k12753




        11.3k12753



























            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%2f53266132%2fprimeng-typeerror-this-activeindex-includes-is-not-a-function%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







            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            Node.js Script on GitHub Pages or Amazon S3

            Museum of Modern and Contemporary Art of Trento and Rovereto