wp-api-angular icon indicating copy to clipboard operation
wp-api-angular copied to clipboard

Dynamic domain

Open vinnchan opened this issue 8 years ago • 6 comments

Hello, how to dynamically change the domain ?

For example: export function WpApiLoaderFactory(http: Http, config:Config) { return new WpApiStaticLoader(http, ${config.domain}/wp-json/, /* namespace is optional, default: '/wp/v2' */); }

Thank you.

vinnchan avatar Mar 11 '17 06:03 vinnchan

Hi Vinnchan,you could do it like this,

export const SITE_URL:string = "config.domain";

in a file then import it in the file where you are calling it,like:

wpApiURL: string = SITE_URL + '/wp-json/wp/v2';

finessed avatar Mar 11 '17 10:03 finessed

Sorry, I think my last question was ambiguous. I get my domain url from an rest API beforehand. This domain url change according to what user type in. The $config.domain below is actually an url value I get from rest API and I assign it to config.domain. Below example is an interpolation: ${config.domain}/wp-json/

export function WpApiLoaderFactory(http: Http, config:Config) { return new WpApiStaticLoader(http, ${config.domain}/wp-json/, /* namespace is optional, default: '/wp/v2' */); }

The demo only demonstrate assign one domain, I want to know how to assign domain according what domain url value user provide us from a form. Thank you

vinnchan avatar Mar 11 '17 14:03 vinnchan

Interesting question. I am not sure how to do this for now with AoT support. Might be worth looking at libraries such as angularfire2 to see if they support dynamic config.

shprink avatar Mar 13 '17 07:03 shprink

any update on this? i need that dynamic change too...

vhb56 avatar Aug 30 '17 13:08 vhb56

Not possible with the current code. PR welcome

shprink avatar Aug 30 '17 14:08 shprink

any update on this? i need that dynamic change too...

iamandreadompe avatar Jan 01 '20 09:01 iamandreadompe