tag:blogger.com,1999:blog-4455058894110083658.post4743072730296335697..comments2024-02-26T22:59:25.161+00:00Comments on Vardhaman Deshpande: Getting the current context (SPHttpClient, PageContext) in a SharePoint Framework ServiceVardhaman Deshpandehttp://www.blogger.com/profile/17919845281919756108noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-4455058894110083658.post-35692315228257183282017-07-19T13:17:31.762+01:002017-07-19T13:17:31.762+01:00Hi Kishan,
What you will have to do is, build you...Hi Kishan,<br /><br />What you will have to do is, build your service as an SPFx library package and then import the package in your webparts. Unfortunately, this is not supported right now but the good news is that the SPFx team is working on this. Have a look at this UserVoice post: <a href="https://sharepoint.uservoice.com/forums/329220-sharepoint-dev-platform/suggestions/19224202-add-support-for-library-packages-in-the-sharepoint" rel="nofollow">https://sharepoint.uservoice.com/forums/329220-sharepoint-dev-platform/suggestions/19224202-add-support-for-library-packages-in-the-sharepoint</a>Vardhaman Deshpandehttps://www.blogger.com/profile/17919845281919756108noreply@blogger.comtag:blogger.com,1999:blog-4455058894110083658.post-25143649134780511842017-07-05T15:51:58.263+01:002017-07-05T15:51:58.263+01:00Hi Vardhaman,
Thanks for a great write up.
I am f...Hi Vardhaman,<br />Thanks for a great write up. <br />I am facing a challenge: I want to connect two web parts in a way that one updates a variable in the service and other consumes it. Following your example, I added a variable and setters and getters as below:<br /><br />private static _sharedData: string;<br /> public getStringData(): string {<br /> return ListService._sharedData;<br /> }<br /> public setStringData(data: string): void {<br /> ListService._sharedData=data;<br /> }<br /><br />Also added an additional consumer web part as consumer2<br /><br />From the first consumer I set and get the value for _sharedData like this<br /><br /> private async setNewdata() {<br /> await this._listServiceInstance.setStringData('new data');<br /> }<br /> private async getNewData() {<br /> this.properties.description = await this._listServiceInstance.getStringData();<br /> console.log(this.properties.description);<br /> }<br /><br />From the second consumer I only get the data like this:<br /><br />private async getNewData() {<br /> this.properties.description = await this._listServiceInstance.getStringData();<br /> console.log(this.properties.description);<br /> }<br /><br />In first case I see the updated data in the log as 'new data' but in the second case the log shows the data as 'undefined'<br /><br />I presume, both the web parts are creating a separate copies of data. Note that I have marked the variable as static to make it a class level and not specific to any instance.<br />Could you please suggest how to share the context between both the web parts so that they may share and see the data updated by each other and what am I missing here?<br /><br />Thanks in advance,<br />KishanKishanhttps://www.blogger.com/profile/04715895522503941488noreply@blogger.com