我有一个有角度的2应用程序,我通过http请求调用Firebase.但是,任何时候,我尝试运行该函数,我收到此错误:
XMLHttpRequest cannot load https://us-central1-<my-projectId>.cloudfunctions.net/getUserByEmail?email=user@email.com. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. The response had HTTP status code 500.
error_handler.js:54 EXCEPTION: Response with status: 0 for URL: null
ErrorHandler.handleError @ error_handler.js:54
next @ application_ref.js:348
schedulerFn @ async.js:93
SafeSubscriber.__tryOrUnsub @ Subscriber.js:234
SafeSubscriber.next @ Subscriber.js:183
Subscriber._next @ Subscriber.js:125
Subscriber.next @ Subscriber.js:89
Subject.next @ Subject.js:55
EventEmitter.emit @ async.js:79
NgZone.triggerError @ ng_zone.js:333
onHandleError @ ng_zone.js:294
ZoneDelegate.handleError @ zone.js:338
Zone.runTask @ zone.js:169
ZoneTask.invoke @ zone.js:420
Subscriber.js:238 …Run Code Online (Sandbox Code Playgroud) 我的离子2应用程序中有一个简单的功能,可以将文件上传到我的firebase存储服务器.它从相机中抓取base64编码的图像字符串,但是当我不尝试强制它时content-type,它默认为application/octet-stream.当我尝试将元数据添加到putString()方法时,我收到错误.
有谁知道我怎么能这样做putString?
这是我目前的功能:
uploadProfilePhoto(file) {
this.storage.get('user').then(user => {
let id = user.id;
var metadata = {
contentType: 'image/jpeg',
};
let userProfileRef = this.fbStorage.ref(`/users/${id}/profile_photo/profile_photo.jpg`);
userProfileRef.putString(file, metadata).then(snapshot => {
}).catch(error => {
});
})
}
Run Code Online (Sandbox Code Playgroud) 因此,Firebase提供了一种称为"功能"的功能,它本质上是一个nodejs服务器,它具有预先配置的所有Firebase内容,并自动处理所有缩放.我想知道,有没有办法从角度2应用程序调用"函数"index.js文件中的函数?
我需要利用firebase-admin npm模块检查用户的电子邮件是否存在,然后获取该用户的uid(如果有).
根据此链接,我可以设置我的index.js文件,例如:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
// I'm actually not sure if this is how you do this part:
exports.getUserByEmail = (email) => {
return admin.auth().getUserByEmail(email);
}
Run Code Online (Sandbox Code Playgroud)
有没有办法getUserByEmail()在Angular 2应用程序中调用组件内部?
提前致谢!
所以我真的很接近这个问题.基本上,我有登录工作,我有代码设置来监视onAuthStateChanged,但问题是,当我刷新页面,即使用户当前登录,它仍然重定向到/login页面,因为我有auth警卫设置,检查用户是否已登录.
我有一个auth服务设置,可以进行所有身份验证检查.
在我的auth服务构造函数中,这就是我onAuthStateChanged设置代码的地方:
constructor(
private auth: AngularFireAuth,
private router:Router,
private db:AngularFireDatabase,
) {
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// What do I need to put here to ensure that the auth guard goes to the intended route?
}
});
}
Run Code Online (Sandbox Code Playgroud)
这是我的auth guard的canActivate()方法:
canActivate(route:ActivatedRouteSnapshot, state:RouterStateSnapshot):Observable<boolean> {
if(this.authService.getAuthenticated()) {
return Observable.of(true);
} else {
this.router.navigate(['/login']);
}
}
Run Code Online (Sandbox Code Playgroud)
这是getAuthenticated()方法:
getAuthenticated() {
return firebase.auth().currentUser;
}
Run Code Online (Sandbox Code Playgroud)
更新:
以下是用户实际登录时调用的方法.在实际组件中,这是登录方法:
login(data, isValid) {
if(isValid) {
this.authService.login(data.email, data.password)
.then(
(data) …Run Code Online (Sandbox Code Playgroud) javascript firebase angularfire firebase-authentication angular
我正在使用Ionic应用程序中的聊天应用程序的最后一项功能,在该功能中,我试图无限滚动到两个人之间创建的“第一条”消息,这与您使用的任何其他聊天应用程序类似。 Facebook,Skype,Slack等
我遇到的问题是几件事。
当我在<ul>容纳所有消息的上方添加无限滚动代码时,会得到一个200px高的空白(我认为这是加载微调器的原因)。这是我的代码:
<ion-infinite-scroll (ionInfinite)="scrolled($event)"
threshold="10px"
position="top">
<ion-infinite-scroll-content></ion-infinite-scroll-content>
</ion-infinite-scroll>
<ul>
<li *ngFor="let message of messages; let i = index">
... other code to build the message
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)我的聊天设置只捕获特定会话的前10条消息,其想法是,一旦它成为“顶部”无限滚动区域,它就会查询下10条消息,等等。问题是,当聊天加载时,在滚动条向下滚动到屏幕底部以显示最后发送的消息之前,会有片刻的暂停。但是,在那一瞬间,滚动条已经位于页面顶部,这似乎表明<ion-infinite-scroll>要启动该scrolled()功能。
还有其他人遇到过这样的事情吗?呈现页面后,消息将异步加载,因此,我正在尝试找出防止<ion-infinite-scroll>页面加载时触发的最佳方法。我在这里缺少简单的东西吗?
提前致谢!:)
我不确定我做了什么,但我angular-moment-timezone今天安装在我的 Ionic 项目中,让它工作,可以运行ionic serve得很好,但后来我决定删除我的node_modules文件夹。一旦我这样做了,我就跑了npm i,一旦这一切都完成了,无论何时我尝试运行ionic serve,我都会收到以下错误:
Typescript Error
Cannot redeclare block-scoped variable 'tz'.
node_modules/@types/moment-timezone/index.d.ts
undefined
undefined
Typescript Error
Cannot redeclare block-scoped variable 'tz'.
node_modules/angular-moment-timezone/node_modules/@types/moment-timezone/index.d.ts
undefined
undefined
Run Code Online (Sandbox Code Playgroud)
我不知道我做错了什么,到目前为止我还没有找到任何可以提供帮助的东西。有没有其他人遇到过同样的问题?
我有一个函数文件,我目前正在尝试做的就是访问Firebase auth()功能,根据电子邮件检查用户是否存在,然后获取他们的uid.
我有一个Angular 2应用程序,我在其中运行一个http请求来调用该函数,但是每当我尝试运行它时,我都会收到此错误:
Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
/**
* Function to get a user by email
*/
exports.getUserByEmail = functions.https.onRequest((req, res) => {
console.log('req', req);
return admin.auth().getUserByEmail(req.query.email);
});
Run Code Online (Sandbox Code Playgroud)
这种类型的东西不允许在Spark计划中吗?我仍然在开发我的应用程序,这是我现在唯一需要工作的东西,我宁愿不必立即开始付费只是为了使用这个小功能.有什么我能做的吗?
提前致谢!
我的网格中有一些代码,我试图防止双击事件导致树行展开/折叠,但我在任何地方都找不到如何执行此操作的文档。我想这样做的原因是,当我双击单元格时,我想让它可编辑,但由于一些技术上的需要,我需要gridApi.redrawRows()在折叠/展开发生时运行,这会导致编辑字段失去焦点,这意味着我永远无法通过双击来实际编辑单元格。
我正在使用以下 ag-grid 模块版本
"ag-grid-angular": "^22.1.1",
"ag-grid-community": "^22.1.1",
"ag-grid-enterprise": "^22.1.1"
Run Code Online (Sandbox Code Playgroud)
我的网格中的相关 html 看起来像这样
<ag-grid-angular
#agGrid
class="ag-theme-balham"
[modules]="modules"
[columnDefs]="columnDefs"
[rowData]="rowData"
[treeData]="true"
(rowGroupOpened)="onRowGroupOpened($event)"
(cellDoubleClicked)="handleCellDoubleClicked($event)"
[getDataPath]="getDataPath"
[defaultColDef]="defaultColDef"
[frameworkComponents]="frameworkComponents"
[autoGroupColumnDef]="autoGroupColumnDef"
(gridReady)="onGridReady($event)"
[getRowNodeId]="getRowNodeId"
>
</ag-grid-angular>
Run Code Online (Sandbox Code Playgroud)
在我的组件文件中,负责以树格式自动分组行的特定列如下所示
ngOnInit() {
this.autoGroupColumnDef = {
editable: this.isAllowedtoEdit,
headerName: "Account #",
sortable: true,
lockPosition: true,
resizable: true,
field: "accountNum",
filter: "agGroupCellRenderer",
cellRendererParams: {
suppressCount: true,
innerRenderer: 'AccountNameColumnDisplayer',
},
};
}
Run Code Online (Sandbox Code Playgroud)
处理双击单元格的函数是这样的:
handleCellDoubleClicked(cell) {
if(cell.column.colDef.field === 'accountNum') {
cell.event.stopPropagation();
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
我的handleCellDoubleClicked()功能似乎没有做任何事情。它运行,但当我双击时该行仍然展开/折叠。
我什至尝试过这个只是为了看看它会做什么,它导致了一些非常奇怪的行为发生
handleCellDoubleClicked(cell) { …Run Code Online (Sandbox Code Playgroud) 我对Redux比较陌生,而且我的表单有一些无线电输入"是"或"否".基本上,我想有条件地显示另一个包含另一个redux表单字段的元素,基于该无线电输入选择.有没有直接做到这一点?
我试图检查formProps.site_visit值,但是我得到一个关于它未定义的错误.为了记录,为了简洁起见,我大大减少了这个组件中的代码量.
export class RequestForm extends React.Component {
submit(formProps) {
const request = {
square_footage: formProps.get('square_footage'),
site_visit: formProps.get('site_visit'),
};
this.props.dispatch(createRequest(request));
}
// Redux Form Props.
const { handleSubmit, pristine, reset, submitting } = this.props
return (
<form className="page-form__wrapper">
<div className="page-form__block">
<div className="page-form__block">
<p> Is a site visit required to complete this request? </p>
<Field name="site_visit"
component={RadioButtonGroup}
>
<RadioButton value="true" label="Yes" />
<RadioButton value="false" label="No" />
</Field>
</div>
{this.formProps.site_visit === true &&
<div className="page-form__block">
<p> Estimate the total area …Run Code Online (Sandbox Code Playgroud) 我正在尝试更新未绑定到<form>组件中的输入的值,而我的研究使我开始使用Renderer2Angular提供的服务。
所以我的输入看起来像这样:
<input type="text" #zipEl placeholder="Enter zip">
<button type="button" (click)="getLocation()">
<span>Use current location</span>
</button>
Run Code Online (Sandbox Code Playgroud)
在我的组件中,我试图像这样简单地设置值:
@ViewChild('zipEl') zipEl:ElementRef;
constructor(private renderer: Renderer2) {
}
getLocation() {
this.renderer.setValue(this.zipEl, '94085');
}
Run Code Online (Sandbox Code Playgroud)
虽然什么都没有发生。当我单击按钮运行该功能时,输入框永远不会更新其值94085。有人知道我在做什么错吗?
提前致谢!
angular ×6
firebase ×5
ionic2 ×3
ag-grid ×1
angularfire ×1
ionic3 ×1
javascript ×1
reactjs ×1
redux-form ×1
typescript ×1