经过一年多的发展,我有一个相当完善的网站。现在我要打开它进行公开测试,但我需要清除我的 Firestore 中的所有数据(都是测试数据)。有没有一种简单的方法可以做到这一点,还是我必须手动删除每个条目?(有超过 1000 个条目)。目前我能想到的唯一现实选择是将 Firebase 项目切换到一个新项目,这不是我想做的事情。
解决方案:在联系 Firebase 支持后,我得到了以下 CLI 命令来运行,它起到了作用:
// THIS WILL PROMPT CONFIRMATION AND WILL USE ACTIVE PROJECT
firebase firestore:delete --all-collections
// !!! WARNING !!! THIS WILL NOT PROMPT CONFIRMATION AND WILL USE ACTIVE PROJECT
firebase firestore:delete --all-collections -y
Run Code Online (Sandbox Code Playgroud)
请记住谨慎使用,因为这会擦除您的整个 Firestore 数据库。
我刚刚注册了 SendGrid,我需要将这些(上图)SendGrid CNAME 记录添加到我的 Google 域中。问题是它没有告诉我在第一个字段(“@”)中放入什么。如果我将其留空,则会出现错误(见下图)。请帮忙。
PS:www根据Google Domains 帮助页面添加给我一个命名冲突,因为已经有一个带有www.
这个mat-select元素很有趣.见下文.
码
<mat-form-field>
<input matInput placeholder="Name" #NameInput>
</mat-form-field>
<mat-select placeholder="How Many?">
<mat-option>One</mat-option>
<mat-option>Two</mat-option>
<mat-option>Three</mat-option>
<mat-option>Four</mat-option>
<mat-option>Five</mat-option>
</mat-select>
Run Code Online (Sandbox Code Playgroud)
结果
包装mat-select中的a mat-form-field给出了以下错误:
mat-form-field必须包含MatFormFieldControl.您是否忘记将matInput添加到本机输入或textarea元素?
然而,包括input与matInput内容显示了input和mat-select在一起,使它看起来怪异.有什么方法吗?
我最近将我的 Angular 5 项目更新为 Angular 6,并且我一整天都在尝试构建和部署。我的最新问题是导入问题 - 之前工作正常。
错误现在cannot find module 'firebase'在我的导入中说。
我正在尝试获取对文档 UID 的引用,以便我可以通过其 UID 在项目中的其他位置使用该文档。根据文档,我正在使用 AngularFire2 (v5) 执行以下操作:
var ref= this.afs.collection(placeToAdd).doc();
Run Code Online (Sandbox Code Playgroud)
这给了我以下错误:“预期 1 个参数,但得到 0”。它希望我在 doc() 方法中添加一个参数。所以,我这样做:
var ref= this.afs.collection(placeToAdd).doc(thing);
Run Code Online (Sandbox Code Playgroud)
然后我设置我的 Firebase 对象:
ref.set({
item1: 'value 1',
item2: 'value 2',
item3: 'value 3'
});
Run Code Online (Sandbox Code Playgroud)
现在如何获取引用的 Firestore 生成的 UID?
我在将Firestore数据转换为chart.js图的数组时遇到困难。
从Firestore获取数据
fetchData(){
//Get data
this.updatesCollection = this.afs.collection(pathStats);
this.updates = this.updatesCollection.valueChanges();
}
Run Code Online (Sandbox Code Playgroud)
创建图表
createChart(){
this.chart = new Chart('canvas', {
type: 'line',
data: {
labels: ['5/18/18', '5/19/18', '5/20/18', '5/21/18', '5/22/18', '5/23/18'],
datasets: [{
label: 'Filled',
backgroundColor: 'gray',
data: [4, 3, 5, 2, 6, 7],
fill: true,
}]
},
}
)
Run Code Online (Sandbox Code Playgroud)
我现在正在使用硬编码值[4, 3, 5, 2, 6, 7]作为数据点的占位符。我将如何使用来自Firestore的值?
解
如以下Ohad所述:
let chartData;
this.updatesCollection.ref.get().then((querySnapshot) => {
chartData = querySnapshot.docs.map(doc => doc.data());
}
Run Code Online (Sandbox Code Playgroud)
这样可以得到一个数组,每个文档都在其自己的索引中。您可以像访问其他任何对象一样访问单个属性(即chartData[0].wheelCount)。
我的布局与工具栏重叠.我必须在工具栏下方添加一个56dp的填充,这使得它很难处理(也可能意味着我不能使用AlignParentTop).片段屏幕(activity_login.xml)几乎是谷歌提供的代码.
(没有填充)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
tools:context="com.myProject.LoginActivity"
android:id="@+id/login2LinearLayout"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin">
<!-- Login progress -->
<ProgressBar
android:id="@+id/login_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:visibility="gone" />
<ScrollView
android:id="@+id/login_form"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/email_login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/prompt_email"
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/prompt_password"
android:imeActionId="@+id/login"
android:imeActionLabel="@string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="@+id/email_sign_in_button"
style="?android:textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/action_sign_in"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
app_bar_main.xml
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" …Run Code Online (Sandbox Code Playgroud) 我的用户可以将条目添加到滚动列表的底部。但是,添加条目时滚动条不会自动向下移动,因此用户无法看到他们新添加的条目。如何让我的滚动条始终处于向下滚动的位置以显示最新条目(使用 Angular 5)?
我需要检查用户是否是第一次登录,如果为真,则使用额外的属性(积分、会员、accountCreationDate 等)初始化他们的帐户。我的代码目前只让用户登录。我正在关注文档 ( https://firebase.google.com/docs/auth/web/google-signin )(第 5 步)。
firebase firebase-authentication angular google-cloud-firestore
我在打字稿文件中收到警告“检测到无法访问的代码”。运行 Firebase 事务后没有任何效果。这是交易代码:
// Create Firestore reference
let pointsRef = 'Users/'+this.user.uid;
var pointsDocRef = this.afs.doc(pointsRef).ref;
return this.afs.firestore.runTransaction((transaction) => {
return transaction.get(pointsDocRef).then((ptsDoc) => {
if(!ptsDoc.exists){
throw "Document does not exist!"
}
var newPtsScore = ptsDoc.data().points - 20;
transaction.update(pointsDocRef, { points: newPtsScore });
});
}).then(() => {
console.log('Point count successfully decremented for new item');
// Close dialog
this.dialog.closeAll();
}).catch(function(error) {console.log('Transaction failed: ', error);});
console.log('Hey there!'); <-- "UNREACHABLE CODE DETECTED"
Run Code Online (Sandbox Code Playgroud)
javascript unreachable-code firebase angular google-cloud-firestore