How to show table if it has data from api otherwise show other div The Next CEO of Stack OverflowHow do I import other TypeScript files?How to get query params from url in Angular 2?How do I pass data to Angular routed components?Angular 2/4 console.log array empty, gettting data from service is async, so it is not going to have data availableUsing *ngFor in CSS Grid Layout Undesirably Displaying Everything in One ColumnHow to retrieve nested values after subscribing using angular and json data?how to check ng-if after change eventAngular 6 UI not updatedThe data I am receiving from GET method is not being updated on html pageAngular 7 : Data looks empty
How to Reset Passwords on Multiple Websites Easily?
Can I equip Skullclamp on a creature I am sacrificing?
Example of a Mathematician/Physicist whose Other Publications during their PhD eclipsed their PhD Thesis
Apart from "berlinern", do any other German dialects have a corresponding verb?
Implement the Thanos sorting algorithm
What can we do to stop prior company from asking us questions?
Why didn't Theresa May consult with Parliament before negotiating a deal with the EU?
Which organization defines CJK Unified Ideographs?
Why do professional authors make "consistency" mistakes? And how to avoid them?
How to get regions to plot as graphics
Inappropriate reference requests from Journal reviewers
Text adventure game code
How easy is it to start Magic from scratch?
How to be diplomatic in refusing to write code that breaches the privacy of our users
Why doesn't a table tennis ball float on the surface? How do we calculate buoyancy here?
Can a single photon have an energy density?
Should I tutor a student who I know has cheated on their homework?
What is the difference between "behavior" and "behaviour"?
How to count occurrences of text in a file?
Shade part of a Venn diagram
Why does C# sound extremely flat when saxophone is tuned to G?
Why did we only see the N-1 starfighters in one film?
How do we know the LHC results are robust?
How to make a software documentation "officially" citable?
How to show table if it has data from api otherwise show other div
The Next CEO of Stack OverflowHow do I import other TypeScript files?How to get query params from url in Angular 2?How do I pass data to Angular routed components?Angular 2/4 console.log array empty, gettting data from service is async, so it is not going to have data availableUsing *ngFor in CSS Grid Layout Undesirably Displaying Everything in One ColumnHow to retrieve nested values after subscribing using angular and json data?how to check ng-if after change eventAngular 6 UI not updatedThe data I am receiving from GET method is not being updated on html pageAngular 7 : Data looks empty
In my Angular 6 application. I have a table showing data from a web api, also I have some ngIf
containers. One shows a message if the web api data is empty. The other one should show the table if there is data coming back in. My current code does not work:
.ts file
public errorApi = false;
public tableShow = false;
ngOnInit()
this.service.getIncidents(this.customer_id).subscribe((data) => data.result.length === 0;
this.tableShow = this.data && this.data.result;
)
}
html
<ng-container *ngIf="errorApi">
<div class="column col-12 text-center pt-10 pb-10">
<div class="empty">
<div class="empty-icon">
<i class="icon icon-people"></i>
</div>
<p class="empty-title h5">There are no incidents to display</p>
<div class="empty-action">
<button class="btn btn-primary">Create an incident</button>
</div>
</div>
</div>
</ng-container>
<ng-container *ngIf="tableshow">
<table></table>
</ng-container>
angular typescript
add a comment |
In my Angular 6 application. I have a table showing data from a web api, also I have some ngIf
containers. One shows a message if the web api data is empty. The other one should show the table if there is data coming back in. My current code does not work:
.ts file
public errorApi = false;
public tableShow = false;
ngOnInit()
this.service.getIncidents(this.customer_id).subscribe((data) => data.result.length === 0;
this.tableShow = this.data && this.data.result;
)
}
html
<ng-container *ngIf="errorApi">
<div class="column col-12 text-center pt-10 pb-10">
<div class="empty">
<div class="empty-icon">
<i class="icon icon-people"></i>
</div>
<p class="empty-title h5">There are no incidents to display</p>
<div class="empty-action">
<button class="btn btn-primary">Create an incident</button>
</div>
</div>
</div>
</ng-container>
<ng-container *ngIf="tableshow">
<table></table>
</ng-container>
angular typescript
When you are doingthis.data = data.result
why are you checkingthis.data && this.data.result
?
– sabithpocker
Mar 8 at 13:22
If there is data or is null
– Sole
Mar 8 at 13:22
I guess you should only be checkingthis.tableShow = this.data
asthis.data
already hasdata.result
? Or did you meanthis.data.length
?
– sabithpocker
Mar 8 at 13:23
add a comment |
In my Angular 6 application. I have a table showing data from a web api, also I have some ngIf
containers. One shows a message if the web api data is empty. The other one should show the table if there is data coming back in. My current code does not work:
.ts file
public errorApi = false;
public tableShow = false;
ngOnInit()
this.service.getIncidents(this.customer_id).subscribe((data) => data.result.length === 0;
this.tableShow = this.data && this.data.result;
)
}
html
<ng-container *ngIf="errorApi">
<div class="column col-12 text-center pt-10 pb-10">
<div class="empty">
<div class="empty-icon">
<i class="icon icon-people"></i>
</div>
<p class="empty-title h5">There are no incidents to display</p>
<div class="empty-action">
<button class="btn btn-primary">Create an incident</button>
</div>
</div>
</div>
</ng-container>
<ng-container *ngIf="tableshow">
<table></table>
</ng-container>
angular typescript
In my Angular 6 application. I have a table showing data from a web api, also I have some ngIf
containers. One shows a message if the web api data is empty. The other one should show the table if there is data coming back in. My current code does not work:
.ts file
public errorApi = false;
public tableShow = false;
ngOnInit()
this.service.getIncidents(this.customer_id).subscribe((data) => data.result.length === 0;
this.tableShow = this.data && this.data.result;
)
}
html
<ng-container *ngIf="errorApi">
<div class="column col-12 text-center pt-10 pb-10">
<div class="empty">
<div class="empty-icon">
<i class="icon icon-people"></i>
</div>
<p class="empty-title h5">There are no incidents to display</p>
<div class="empty-action">
<button class="btn btn-primary">Create an incident</button>
</div>
</div>
</div>
</ng-container>
<ng-container *ngIf="tableshow">
<table></table>
</ng-container>
angular typescript
angular typescript
edited Mar 8 at 13:26
Zoe
13k85085
13k85085
asked Mar 8 at 13:12
SoleSole
4264925
4264925
When you are doingthis.data = data.result
why are you checkingthis.data && this.data.result
?
– sabithpocker
Mar 8 at 13:22
If there is data or is null
– Sole
Mar 8 at 13:22
I guess you should only be checkingthis.tableShow = this.data
asthis.data
already hasdata.result
? Or did you meanthis.data.length
?
– sabithpocker
Mar 8 at 13:23
add a comment |
When you are doingthis.data = data.result
why are you checkingthis.data && this.data.result
?
– sabithpocker
Mar 8 at 13:22
If there is data or is null
– Sole
Mar 8 at 13:22
I guess you should only be checkingthis.tableShow = this.data
asthis.data
already hasdata.result
? Or did you meanthis.data.length
?
– sabithpocker
Mar 8 at 13:23
When you are doing
this.data = data.result
why are you checking this.data && this.data.result
?– sabithpocker
Mar 8 at 13:22
When you are doing
this.data = data.result
why are you checking this.data && this.data.result
?– sabithpocker
Mar 8 at 13:22
If there is data or is null
– Sole
Mar 8 at 13:22
If there is data or is null
– Sole
Mar 8 at 13:22
I guess you should only be checking
this.tableShow = this.data
as this.data
already has data.result
? Or did you mean this.data.length
?– sabithpocker
Mar 8 at 13:23
I guess you should only be checking
this.tableShow = this.data
as this.data
already has data.result
? Or did you mean this.data.length
?– sabithpocker
Mar 8 at 13:23
add a comment |
4 Answers
4
active
oldest
votes
Use the data variable directly to check if it has data or not.
This checks if you have data in the data
array. If it has, it will display the table but if it's empty array or null then it will display the error.
Define your data variable in the ts
first:data = [];
<div *ngIf="!data.length > 0">
<div class="column col-12 text-center pt-10 pb-10">
<div class="empty">
<div class="empty-icon">
<i class="icon icon-people"></i>
</div>
<p class="empty-title h5">There are no incidents to display</p>
<div class="empty-action">
<button class="btn btn-primary">Create an incident</button>
</div>
</div>
</div>
</div>
<div *ngIf="data.length > 0">
<p>Table Data here</p>
</div>
I get an error Cannot read property 'length' of undefined?
– Sole
Mar 8 at 13:28
1
@MaihanNijat in order to avoid undefined you have to initializedata
while declaredata = []
in ts file. Right now angular template doesnot aware if data is going to be an or []
– mumair
Mar 8 at 13:39
1
other good solution isasync
pipe
– mumair
Mar 8 at 13:40
My data is defined in the .ts file aspublic data: any;
– Sole
Mar 8 at 16:39
Still get that error: error Cannot read property 'length' of undefined?
– Sole
Mar 8 at 16:39
|
show 4 more comments
Try else in ngIf statement
<ng-container *ngIf="errorApi else apiTable">
<div class="column col-12 text-center pt-10 pb-10">
<div class="empty">
<div class="empty-icon">
<i class="icon icon-people"></i>
</div>
<p class="empty-title h5">There are no incidents to display</p>
<div class="empty-action">
<button class="btn btn-primary">Create an incident</button>
</div>
</div>
</div>
</ng-container>
<ng-container #apiTable>
<table></table>
</ng-container>
add a comment |
Try else
from *ngIf
directive:
*ngIf="errorApi; else apiTable"
In the original question there is no "apiTable"
– A. Roussos
Mar 8 at 13:46
add a comment |
public data: any;
public loading: boolean;
private subscription: Subscription;
ngOnInit()
this.loading = true;
this.subscription = this.service.getIncidents(this.customer_id)
.subscribe((data: any) =>
this.loading = false;
// Because you have no error logic in your service
If (data.result //&& any other validation on the data: )
this.data = data.result;
console.log('Result - ', data);
console.log('data is received');
else
this.errorApi = true;
);
ngOnDestroy(): void
this.subscription.unsubscribe();
And in your html you can use ng-template
:
<ng-template *ngIf="data && !loading; else errorTemplate">...</ng-template>
<ng-template #errorTemplate>...</ng-template>
Obviously, accommodate for your validation on the data: but this should provide you some ideas.
Ideally you should implement your service to return the data as valid and use (error: any) => to account for the errors you may encounter. That way you don't have to check twice for the data and you can simply use this.data as a check in your DOM as oppose to all the other conditions on the object you are currently using.
– mzaleski
Mar 8 at 13:44
add a comment |
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
);
);
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55063960%2fhow-to-show-table-if-it-has-data-from-api-otherwise-show-other-div%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use the data variable directly to check if it has data or not.
This checks if you have data in the data
array. If it has, it will display the table but if it's empty array or null then it will display the error.
Define your data variable in the ts
first:data = [];
<div *ngIf="!data.length > 0">
<div class="column col-12 text-center pt-10 pb-10">
<div class="empty">
<div class="empty-icon">
<i class="icon icon-people"></i>
</div>
<p class="empty-title h5">There are no incidents to display</p>
<div class="empty-action">
<button class="btn btn-primary">Create an incident</button>
</div>
</div>
</div>
</div>
<div *ngIf="data.length > 0">
<p>Table Data here</p>
</div>
I get an error Cannot read property 'length' of undefined?
– Sole
Mar 8 at 13:28
1
@MaihanNijat in order to avoid undefined you have to initializedata
while declaredata = []
in ts file. Right now angular template doesnot aware if data is going to be an or []
– mumair
Mar 8 at 13:39
1
other good solution isasync
pipe
– mumair
Mar 8 at 13:40
My data is defined in the .ts file aspublic data: any;
– Sole
Mar 8 at 16:39
Still get that error: error Cannot read property 'length' of undefined?
– Sole
Mar 8 at 16:39
|
show 4 more comments
Use the data variable directly to check if it has data or not.
This checks if you have data in the data
array. If it has, it will display the table but if it's empty array or null then it will display the error.
Define your data variable in the ts
first:data = [];
<div *ngIf="!data.length > 0">
<div class="column col-12 text-center pt-10 pb-10">
<div class="empty">
<div class="empty-icon">
<i class="icon icon-people"></i>
</div>
<p class="empty-title h5">There are no incidents to display</p>
<div class="empty-action">
<button class="btn btn-primary">Create an incident</button>
</div>
</div>
</div>
</div>
<div *ngIf="data.length > 0">
<p>Table Data here</p>
</div>
I get an error Cannot read property 'length' of undefined?
– Sole
Mar 8 at 13:28
1
@MaihanNijat in order to avoid undefined you have to initializedata
while declaredata = []
in ts file. Right now angular template doesnot aware if data is going to be an or []
– mumair
Mar 8 at 13:39
1
other good solution isasync
pipe
– mumair
Mar 8 at 13:40
My data is defined in the .ts file aspublic data: any;
– Sole
Mar 8 at 16:39
Still get that error: error Cannot read property 'length' of undefined?
– Sole
Mar 8 at 16:39
|
show 4 more comments
Use the data variable directly to check if it has data or not.
This checks if you have data in the data
array. If it has, it will display the table but if it's empty array or null then it will display the error.
Define your data variable in the ts
first:data = [];
<div *ngIf="!data.length > 0">
<div class="column col-12 text-center pt-10 pb-10">
<div class="empty">
<div class="empty-icon">
<i class="icon icon-people"></i>
</div>
<p class="empty-title h5">There are no incidents to display</p>
<div class="empty-action">
<button class="btn btn-primary">Create an incident</button>
</div>
</div>
</div>
</div>
<div *ngIf="data.length > 0">
<p>Table Data here</p>
</div>
Use the data variable directly to check if it has data or not.
This checks if you have data in the data
array. If it has, it will display the table but if it's empty array or null then it will display the error.
Define your data variable in the ts
first:data = [];
<div *ngIf="!data.length > 0">
<div class="column col-12 text-center pt-10 pb-10">
<div class="empty">
<div class="empty-icon">
<i class="icon icon-people"></i>
</div>
<p class="empty-title h5">There are no incidents to display</p>
<div class="empty-action">
<button class="btn btn-primary">Create an incident</button>
</div>
</div>
</div>
</div>
<div *ngIf="data.length > 0">
<p>Table Data here</p>
</div>
edited Mar 8 at 17:06
answered Mar 8 at 13:18
Maihan NijatMaihan Nijat
2,94822448
2,94822448
I get an error Cannot read property 'length' of undefined?
– Sole
Mar 8 at 13:28
1
@MaihanNijat in order to avoid undefined you have to initializedata
while declaredata = []
in ts file. Right now angular template doesnot aware if data is going to be an or []
– mumair
Mar 8 at 13:39
1
other good solution isasync
pipe
– mumair
Mar 8 at 13:40
My data is defined in the .ts file aspublic data: any;
– Sole
Mar 8 at 16:39
Still get that error: error Cannot read property 'length' of undefined?
– Sole
Mar 8 at 16:39
|
show 4 more comments
I get an error Cannot read property 'length' of undefined?
– Sole
Mar 8 at 13:28
1
@MaihanNijat in order to avoid undefined you have to initializedata
while declaredata = []
in ts file. Right now angular template doesnot aware if data is going to be an or []
– mumair
Mar 8 at 13:39
1
other good solution isasync
pipe
– mumair
Mar 8 at 13:40
My data is defined in the .ts file aspublic data: any;
– Sole
Mar 8 at 16:39
Still get that error: error Cannot read property 'length' of undefined?
– Sole
Mar 8 at 16:39
I get an error Cannot read property 'length' of undefined?
– Sole
Mar 8 at 13:28
I get an error Cannot read property 'length' of undefined?
– Sole
Mar 8 at 13:28
1
1
@MaihanNijat in order to avoid undefined you have to initialize
data
while declare data = []
in ts file. Right now angular template doesnot aware if data is going to be an or []– mumair
Mar 8 at 13:39
@MaihanNijat in order to avoid undefined you have to initialize
data
while declare data = []
in ts file. Right now angular template doesnot aware if data is going to be an or []– mumair
Mar 8 at 13:39
1
1
other good solution is
async
pipe– mumair
Mar 8 at 13:40
other good solution is
async
pipe– mumair
Mar 8 at 13:40
My data is defined in the .ts file as
public data: any;
– Sole
Mar 8 at 16:39
My data is defined in the .ts file as
public data: any;
– Sole
Mar 8 at 16:39
Still get that error: error Cannot read property 'length' of undefined?
– Sole
Mar 8 at 16:39
Still get that error: error Cannot read property 'length' of undefined?
– Sole
Mar 8 at 16:39
|
show 4 more comments
Try else in ngIf statement
<ng-container *ngIf="errorApi else apiTable">
<div class="column col-12 text-center pt-10 pb-10">
<div class="empty">
<div class="empty-icon">
<i class="icon icon-people"></i>
</div>
<p class="empty-title h5">There are no incidents to display</p>
<div class="empty-action">
<button class="btn btn-primary">Create an incident</button>
</div>
</div>
</div>
</ng-container>
<ng-container #apiTable>
<table></table>
</ng-container>
add a comment |
Try else in ngIf statement
<ng-container *ngIf="errorApi else apiTable">
<div class="column col-12 text-center pt-10 pb-10">
<div class="empty">
<div class="empty-icon">
<i class="icon icon-people"></i>
</div>
<p class="empty-title h5">There are no incidents to display</p>
<div class="empty-action">
<button class="btn btn-primary">Create an incident</button>
</div>
</div>
</div>
</ng-container>
<ng-container #apiTable>
<table></table>
</ng-container>
add a comment |
Try else in ngIf statement
<ng-container *ngIf="errorApi else apiTable">
<div class="column col-12 text-center pt-10 pb-10">
<div class="empty">
<div class="empty-icon">
<i class="icon icon-people"></i>
</div>
<p class="empty-title h5">There are no incidents to display</p>
<div class="empty-action">
<button class="btn btn-primary">Create an incident</button>
</div>
</div>
</div>
</ng-container>
<ng-container #apiTable>
<table></table>
</ng-container>
Try else in ngIf statement
<ng-container *ngIf="errorApi else apiTable">
<div class="column col-12 text-center pt-10 pb-10">
<div class="empty">
<div class="empty-icon">
<i class="icon icon-people"></i>
</div>
<p class="empty-title h5">There are no incidents to display</p>
<div class="empty-action">
<button class="btn btn-primary">Create an incident</button>
</div>
</div>
</div>
</ng-container>
<ng-container #apiTable>
<table></table>
</ng-container>
answered Mar 8 at 13:19
A. RoussosA. Roussos
17719
17719
add a comment |
add a comment |
Try else
from *ngIf
directive:
*ngIf="errorApi; else apiTable"
In the original question there is no "apiTable"
– A. Roussos
Mar 8 at 13:46
add a comment |
Try else
from *ngIf
directive:
*ngIf="errorApi; else apiTable"
In the original question there is no "apiTable"
– A. Roussos
Mar 8 at 13:46
add a comment |
Try else
from *ngIf
directive:
*ngIf="errorApi; else apiTable"
Try else
from *ngIf
directive:
*ngIf="errorApi; else apiTable"
edited Mar 8 at 14:22
mumair
1,6171934
1,6171934
answered Mar 8 at 13:21
Yuri KevinYuri Kevin
212
212
In the original question there is no "apiTable"
– A. Roussos
Mar 8 at 13:46
add a comment |
In the original question there is no "apiTable"
– A. Roussos
Mar 8 at 13:46
In the original question there is no "apiTable"
– A. Roussos
Mar 8 at 13:46
In the original question there is no "apiTable"
– A. Roussos
Mar 8 at 13:46
add a comment |
public data: any;
public loading: boolean;
private subscription: Subscription;
ngOnInit()
this.loading = true;
this.subscription = this.service.getIncidents(this.customer_id)
.subscribe((data: any) =>
this.loading = false;
// Because you have no error logic in your service
If (data.result //&& any other validation on the data: )
this.data = data.result;
console.log('Result - ', data);
console.log('data is received');
else
this.errorApi = true;
);
ngOnDestroy(): void
this.subscription.unsubscribe();
And in your html you can use ng-template
:
<ng-template *ngIf="data && !loading; else errorTemplate">...</ng-template>
<ng-template #errorTemplate>...</ng-template>
Obviously, accommodate for your validation on the data: but this should provide you some ideas.
Ideally you should implement your service to return the data as valid and use (error: any) => to account for the errors you may encounter. That way you don't have to check twice for the data and you can simply use this.data as a check in your DOM as oppose to all the other conditions on the object you are currently using.
– mzaleski
Mar 8 at 13:44
add a comment |
public data: any;
public loading: boolean;
private subscription: Subscription;
ngOnInit()
this.loading = true;
this.subscription = this.service.getIncidents(this.customer_id)
.subscribe((data: any) =>
this.loading = false;
// Because you have no error logic in your service
If (data.result //&& any other validation on the data: )
this.data = data.result;
console.log('Result - ', data);
console.log('data is received');
else
this.errorApi = true;
);
ngOnDestroy(): void
this.subscription.unsubscribe();
And in your html you can use ng-template
:
<ng-template *ngIf="data && !loading; else errorTemplate">...</ng-template>
<ng-template #errorTemplate>...</ng-template>
Obviously, accommodate for your validation on the data: but this should provide you some ideas.
Ideally you should implement your service to return the data as valid and use (error: any) => to account for the errors you may encounter. That way you don't have to check twice for the data and you can simply use this.data as a check in your DOM as oppose to all the other conditions on the object you are currently using.
– mzaleski
Mar 8 at 13:44
add a comment |
public data: any;
public loading: boolean;
private subscription: Subscription;
ngOnInit()
this.loading = true;
this.subscription = this.service.getIncidents(this.customer_id)
.subscribe((data: any) =>
this.loading = false;
// Because you have no error logic in your service
If (data.result //&& any other validation on the data: )
this.data = data.result;
console.log('Result - ', data);
console.log('data is received');
else
this.errorApi = true;
);
ngOnDestroy(): void
this.subscription.unsubscribe();
And in your html you can use ng-template
:
<ng-template *ngIf="data && !loading; else errorTemplate">...</ng-template>
<ng-template #errorTemplate>...</ng-template>
Obviously, accommodate for your validation on the data: but this should provide you some ideas.
public data: any;
public loading: boolean;
private subscription: Subscription;
ngOnInit()
this.loading = true;
this.subscription = this.service.getIncidents(this.customer_id)
.subscribe((data: any) =>
this.loading = false;
// Because you have no error logic in your service
If (data.result //&& any other validation on the data: )
this.data = data.result;
console.log('Result - ', data);
console.log('data is received');
else
this.errorApi = true;
);
ngOnDestroy(): void
this.subscription.unsubscribe();
And in your html you can use ng-template
:
<ng-template *ngIf="data && !loading; else errorTemplate">...</ng-template>
<ng-template #errorTemplate>...</ng-template>
Obviously, accommodate for your validation on the data: but this should provide you some ideas.
answered Mar 8 at 13:37
mzaleskimzaleski
135
135
Ideally you should implement your service to return the data as valid and use (error: any) => to account for the errors you may encounter. That way you don't have to check twice for the data and you can simply use this.data as a check in your DOM as oppose to all the other conditions on the object you are currently using.
– mzaleski
Mar 8 at 13:44
add a comment |
Ideally you should implement your service to return the data as valid and use (error: any) => to account for the errors you may encounter. That way you don't have to check twice for the data and you can simply use this.data as a check in your DOM as oppose to all the other conditions on the object you are currently using.
– mzaleski
Mar 8 at 13:44
Ideally you should implement your service to return the data as valid and use (error: any) => to account for the errors you may encounter. That way you don't have to check twice for the data and you can simply use this.data as a check in your DOM as oppose to all the other conditions on the object you are currently using.
– mzaleski
Mar 8 at 13:44
Ideally you should implement your service to return the data as valid and use (error: any) => to account for the errors you may encounter. That way you don't have to check twice for the data and you can simply use this.data as a check in your DOM as oppose to all the other conditions on the object you are currently using.
– mzaleski
Mar 8 at 13:44
add a comment |
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.
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55063960%2fhow-to-show-table-if-it-has-data-from-api-otherwise-show-other-div%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
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
When you are doing
this.data = data.result
why are you checkingthis.data && this.data.result
?– sabithpocker
Mar 8 at 13:22
If there is data or is null
– Sole
Mar 8 at 13:22
I guess you should only be checking
this.tableShow = this.data
asthis.data
already hasdata.result
? Or did you meanthis.data.length
?– sabithpocker
Mar 8 at 13:23