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











up vote
0
down vote

favorite












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
    2 days ago















up vote
0
down vote

favorite












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
    2 days ago













up vote
0
down vote

favorite









up vote
0
down vote

favorite











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 22 hours ago









Goncalo Peres

8011311




8011311










asked 2 days ago









Manos Kounelakis

754726




754726












  • 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
    2 days ago


















  • 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
    2 days ago
















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
2 days ago




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
2 days ago












2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted










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
    2 days ago










  • Also notice that If I bind [multiple] to a boolean variable inside my component class the error goes away
    – Manos Kounelakis
    2 days ago










  • 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
    – Catgrammer
    2 days ago












  • @ManosKounelakis take a look to my updated answer
    – Catgrammer
    2 days ago






  • 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
    2 days ago


















up vote
1
down vote













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',
    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
































    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    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
      2 days ago










    • Also notice that If I bind [multiple] to a boolean variable inside my component class the error goes away
      – Manos Kounelakis
      2 days ago










    • 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
      – Catgrammer
      2 days ago












    • @ManosKounelakis take a look to my updated answer
      – Catgrammer
      2 days ago






    • 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
      2 days ago















    up vote
    1
    down vote



    accepted










    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
      2 days ago










    • Also notice that If I bind [multiple] to a boolean variable inside my component class the error goes away
      – Manos Kounelakis
      2 days ago










    • 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
      – Catgrammer
      2 days ago












    • @ManosKounelakis take a look to my updated answer
      – Catgrammer
      2 days ago






    • 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
      2 days ago













    up vote
    1
    down vote



    accepted







    up vote
    1
    down vote



    accepted






    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 2 days ago

























    answered 2 days ago









    Catgrammer

    1,2781523




    1,2781523












    • But what happens If I want to have multiple tabs and the first one selected by default?
      – Manos Kounelakis
      2 days ago










    • Also notice that If I bind [multiple] to a boolean variable inside my component class the error goes away
      – Manos Kounelakis
      2 days ago










    • 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
      – Catgrammer
      2 days ago












    • @ManosKounelakis take a look to my updated answer
      – Catgrammer
      2 days ago






    • 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
      2 days ago


















    • But what happens If I want to have multiple tabs and the first one selected by default?
      – Manos Kounelakis
      2 days ago










    • Also notice that If I bind [multiple] to a boolean variable inside my component class the error goes away
      – Manos Kounelakis
      2 days ago










    • 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
      – Catgrammer
      2 days ago












    • @ManosKounelakis take a look to my updated answer
      – Catgrammer
      2 days ago






    • 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
      2 days ago
















    But what happens If I want to have multiple tabs and the first one selected by default?
    – Manos Kounelakis
    2 days ago




    But what happens If I want to have multiple tabs and the first one selected by default?
    – Manos Kounelakis
    2 days ago












    Also notice that If I bind [multiple] to a boolean variable inside my component class the error goes away
    – Manos Kounelakis
    2 days ago




    Also notice that If I bind [multiple] to a boolean variable inside my component class the error goes away
    – Manos Kounelakis
    2 days ago












    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
    – Catgrammer
    2 days ago






    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
    – Catgrammer
    2 days ago














    @ManosKounelakis take a look to my updated answer
    – Catgrammer
    2 days ago




    @ManosKounelakis take a look to my updated answer
    – Catgrammer
    2 days ago




    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
    2 days ago




    Accepted and upvoted.Took me some hours for a simillar project that would throw me a strange error.Now I got it
    – Manos Kounelakis
    2 days ago












    up vote
    1
    down vote













    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

























      up vote
      1
      down vote













      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























        up vote
        1
        down vote










        up vote
        1
        down vote









        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 2 days ago









        sabithpocker

        11.2k12753




        11.2k12753






























             

            draft saved


            draft discarded



















































             


            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




















































































            Popular posts from this blog

            Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

            ComboBox Display Member on multiple fields

            Is it possible to collect Nectar points via Trainline?