Forum Discussion
Sharepoint framework spfx > get weburl
Hi Mike Jansen,
this.context.pageContext.web.absoluteUrl
is the right way ,but document.ready is not the right way ;-)
you can simply call whatever you need within the render method.
You will have to use methods with a promise like this:
public _getListDataUsers(): Promise<Users> { return this.context.spHttpClient.get(this.context.pageContext.web.absoluteUrl + `/_api/web/siteusers`, SPHttpClient.configurations.v1) .then((response: SPHttpClientResponse) => { return response.json(); }); }
The above example will work within a render method as the context will be alive.
If you for example run the method from a document ready then you will get some errors as you are experiencing.
You will need roughly something like this if you want an onclick event:
var myElement: Element = document.querySelector(`#myElement`); myElement.addEventListener('click', (evt: Event) => { this._getListDataUsers }, false);
- Mike JansenJun 19, 2017Iron Contributor
Hi Pieter Veenstra,
Another newbie question. Now I have my url available within the .ts file. I do need it in my blabla.js file.
How can I pass the value to my .js file? Is there some kind of export function?
Thanks, Mike
- Jun 19, 2017
Hi Mike Jansen,
Why wouldn't you pass the parameters in like you would do with functions?
functionName(parameter1, parameter2, parameter3) { code to be executed }
- Mike JansenJun 19, 2017Iron Contributor
Pieter Veenstra I did that.Must be a problem with my references because it does not seem to find my function.
I'll check my code again. Guess have taken a too complex example for my first project ;-)
- Mike JansenJun 15, 2017Iron Contributor
hi Pieter Veenstra.
Thanks again, I will dive into this.