Access window object in ember-cli environment

守給你的承諾、 提交于 2019-12-07 08:23:37

问题


Hi I am trying to use torii in a cordova application. My environment.js file looks as below. I an not able to access window document object to setup redirectUri. getting error undefined variable. how can I access window document object.

module.exports = function (environment) {
    var ENV = {
        environment: environment,
        baseURL: '/',
        locationType: 'hash',
        EmberENV: {
            FEATURES: {
                // Here you can enable experimental features on an ember canary build
                // e.g. 'with-controller': true
            }
        },
        APP: {
            // Here you can pass flags/options to your application instance
            // when it is created
        },
        torii: {
            providers: {
                'facebook-oauth2': {
                    apiKey: '2xxxxxxxxxx',
                    redirectUri: document.location.href
                },
            }
        },
        cordova: {
            rebuildOnChange: false,
            rebuildAsync: false,
            emulate: false
        }
    };

in my .jshintrc

"predef": {
    "document": true,
    "window": true,
    "AuthENV": true
  }

so I assume document should be globally available but it is not


回答1:


You are able to access the window and document object through most of your Ember.js code as global variables.

In this particular file, you are trying to access it in use for the app config. The problem is that the config is generated during the Node.js build process - meaning that the context is not the same.

You will see in the page source of your app that the config is static and serialized into a meta property in the page:

<meta name="[your-app]/config/environment" content="your-config-here" />

As the redirect url will change dynamically depending on the user's location, it would be easier to pull in this data "just in time" for the OAuth flow.



来源:https://stackoverflow.com/questions/25609303/access-window-object-in-ember-cli-environment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!