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
angular primeng angular7
add a comment |
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
angular primeng angular7
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
add a comment |
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
angular primeng angular7
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
angular primeng angular7
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
add a comment |
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
add a comment |
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>
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
add a comment |
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.
add a comment |
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>
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
add a comment |
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>
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
add a comment |
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>
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>
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
add a comment |
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered 2 days ago
sabithpocker
11.2k12753
11.2k12753
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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