Reputation: 21
How do I ignore the 1st record in a table when using the get and subscribe using Angular? using the code below:-
getAdmins() {
this.data = [];
this.api.getAdminList()
.subscribe(
data => {
this.data = data;
if (this.isFirstLoad) {
this.isFirstLoad = false;
this.dtTrigger.next();
}
}
);
}
My data layout as follow:-
I want to ignore the Administrator record but start to display the record from Mr x onward.
Upvotes: 2
Views: 66
Reputation: 1163
You can try using Array splice
this.api.getAdminList()
.subscribe(
data => {
if(data.length > 0) {
this.data= data.splice(0,1);
}
});
or try reversing the array and then popping the last item
this.api.getAdminList()
.subscribe(
data => {
if(data.length > 0) {
this.data = data.reverse().pop();
}
});
Upvotes: 1
Reputation: 1107
getAdmins() {
this.data = [];
this.api.getAdminList()
.subscribe(
data => {
this.data = data.shift(); //The shift() command will remove the first element of the array
}
);
}
Upvotes: 1
Reputation: 2216
Try:
this.api.getAdminList().pipe()
.subscribe(
data => {
this.data = data.splice(1);
}
);
Upvotes: 0
Reputation: 224
Have you thought about using splice?
this.data = [];
this.api.getAdminList()
.subscribe(
data => {
this.data = data.length > 1 ? data.splice(0, 1) : [];
}
);
https://www.w3schools.com/jsref/jsref_splice.asp
Upvotes: 0