Skip to content Skip to sidebar Skip to footer

Angular Universal + External Api

I know that Angular Universal is still in development. So I have thought about using Angular Universal for a web app that regularly pulls data from an external API server (about ev

Solution 1:

Angular Universal doesn't know if your code is server code or client code, it just take your app and try to render it on the server. but as you mentioned there is a time you want the server to act differently from the client. For example if you have a function that you want that Angular Universal will skip put this line of code at the top of the function body.

if (typeofwindow === "undefined") return;

Or if you have a scenario that you need to server to do something differently from the client do this

if (typeofwindow === "undefined") {
    // server code
} else {
   // client code
};

Solution 2:

Angular Universal have two constants isNode & IsBrowser

if(isNode){

   // it's Node Server

} else {
  //it's Browser
}

Post a Comment for "Angular Universal + External Api"