在ember-cli环境中访问窗口对象 [英] Access window object in ember-cli environment
问题描述
module.exports = function(environment){
var ENV = {
环境:环境,
baseURL:'/',
位置类型:'哈希',
EmberENV:{
FEATURES:{
//这里可以在ember金丝雀上创建实验功能
// eg 'with-controller':true
}
},
APP:{
//这里你可以将标志/选项传递给你的应用程序实例
//当它创建
},
torii:{
providers:{
'facebook-oauth2':{
apiKey:'2xxxxxxxxxx',
redirectUri:document .location.href
},
}
},
cordova:{
rebuildOnChange:false,
rebuildAsync:false,
emulate:假
}
};
在我的.jshintrc
predef:{
document:true,
window:true,
AuthENV:true
}
所以我假设文档应该是全球可用的,但不是
您可以通过多数访问窗口
和文档
的Ember.js代码作为全局变量。
在这个特定的文件中,您正在尝试访问该应用程序配置。问题是,在Node.js构建过程中生成配置 - 这意味着上下文是不一样的。
您将在页面的应用程序源中看到该配置是静态的并序列化为页面中的元属性:
< meta name =[your-app] / config / environmentcontent =your-config-here/>
由于重定向网址会根据用户的位置动态更改,因此更容易数据及时为OAuth流。
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
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.
这篇关于在ember-cli环境中访问窗口对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!