admin管理员组文章数量:1289909
I am attempting to use a Parse server and am currently running into issues with initializing Parse in javascript and pointing to the correct serverURL. Curious if anyone else has had any luck doing this with Angular2 yet?
I am attempting to use a Parse server and am currently running into issues with initializing Parse in javascript and pointing to the correct serverURL. Curious if anyone else has had any luck doing this with Angular2 yet?
Share Improve this question asked Jun 16, 2016 at 20:14 joshsisleyjoshsisley 3102 silver badges11 bronze badges3 Answers
Reset to default 8For frameworks that use typescript (ex. angular 2, ionic 2 & 3),
To solve the typescript read-only error:
Typescript Error
Cannot assign to 'serverURL' because it is a constant or a read-only property.
Parse.serverURL = 'http://localhost:1337/parse';
Use (Parse as any)
instead of Parse
to set the value of serverUrl such as:
import * as Parse from 'parse';
Parse.initialize('appId', 'jsKey'); // use your appID & your js key
(Parse as any).serverURL = 'http://localhost:1337/parse'; // use your server url
This require parse and @types/parse to be installed:
npm install --save @types/parse parse
A bit late but I've found the trick when the typescript throws a Cannot assign to 'serverURL' because it is a constant or a read-only property
// Use parse with typescript
import * as Parse from 'parse';
// To set the server URL
let parse = require('parse');
Now you have access to parse.serverUrl
, which is the same as Parse.serverUrl
except that the TS definition will throw a read-only error.
I'm using Parse server within an Angular 1 application, but the code works for both. I'm initializing Parse in a own Parse service, which provides some handy helper methods. But I think it doesn't matter where you run this code.
var appId = 'appId';
var jsKey = 'jsKey'; // I think this is not used anymore
Parse.initialize(appId, jsKey);
Parse.serverURL = 'yourNewServerUrl.';
本文标签: javascriptHow to initialize Parse and point to serverURL using Angular2Stack Overflow
版权声明:本文标题:javascript - How to initialize Parse and point to serverURL using Angular2 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741443823a2379076.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论