WP-API / client-js

Backbone-based JavaScript client for WP API
267 stars 58 forks source link

wpApiSettings is not defined #87

Closed MurhafSousli closed 8 years ago

MurhafSousli commented 8 years ago

Hi, I tried to include the script wp-api.min.js from the build dir, I get this exception

Uncaught ReferenceError: wpApiSettings is not defined(anonymous function) @ models.js:114

how can I fix this error?

kadamwhite commented 8 years ago

I could be wrong (@adamsilverstein is the authority here), but I believe that this script is designed to be enqueued through WordPress, so that WP's script localization capabilities can inject that configuration object based on your specific WP install. Is there a reason you need to hard-code a script tag for the client JS rather than using the enqueue script method?

rmccue commented 8 years ago

I believe that this script is designed to be enqueued through WordPress

In fact, it's required to be, you can't use it outside of WP.

MurhafSousli commented 8 years ago

I'm using wp rest api to get data for an angular2 app client, which is outside WP

rmccue commented 8 years ago

You need to use an alternative library and authentication method to access the API outside WP.

adamsilverstein commented 8 years ago

@MurhafSousli This library is indeed currently designed to be enqueued from WordPress, however your question brings up an interesting point: can we remove the WordPress dependency?