angularfire2@5.0.0-rc.10 .snapshotChanges() 无法让您获得 doc.payload.doc.data()
angularfire2@5.0.0-rc.10 .snapshotChanges() not able to let you get the doc.payload.doc.data()
版本信息
Angular:6.0.4
Firebase: 5.0.3
Angular火:5.0.0-rc.10
ng-test-angular6@0.0.0 /home/amine/docker-projects/ng-test-angular6
├── @angular-devkit/build-angular@0.6.8
├── @angular/animations@6.0.4
├── @angular/cli@6.0.8
├── @angular/common@6.0.4
├── @angular/compiler@6.0.4
├── @angular/compiler-cli@6.0.4
├── @angular/core@6.0.4
├── @angular/forms@6.0.4
├── @angular/http@6.0.4
├── @angular/language-service@6.0.4
├── @angular/platform-browser@6.0.4
├── @angular/platform-browser-dynamic@6.0.4
├── @angular/router@6.0.4
├── @types/jasmine@2.8.8
├── @types/jasminewd2@2.0.3
├── @types/node@8.9.5
├── angularfire2@5.0.0-rc.10
├── codelyzer@4.2.1
├── core-js@2.5.7
├── firebase@5.0.3
├── jasmine-core@2.99.1
├── jasmine-spec-reporter@4.2.1
├── karma@2.0.2
├── karma-chrome-launcher@2.2.0
├── karma-coverage-istanbul-reporter@2.0.1
├── karma-jasmine@1.1.2
├── karma-jasmine-html-reporter@0.2.2
├── protractor@5.3.2
├── rxjs@6.2.0
├── ts-node@5.0.1
├── tslint@5.9.1
├── typescript@2.7.2
└── zone.js@0.8.26
如何重现这些条件
看看the angular project ng-angular6-angularfire5.0.0-rc.10
只需克隆、安装和服务。
调试输出
问题出在该行中的函数 L20
fetchAvailableExercices() {
this.db.collection('availablesExercices')
.snapshotChanges()
.pipe(map( docArray => {
return docArray.map( doc => {
console.log(doc);
return(
{
id: doc.payload.doc.id,
name: doc.payload.doc.data().name,
duration: doc.payload.doc.data().duration,
calories: doc.payload.doc.data().calories,
}
//doc
);
});
}))
.subscribe(exercices => {
this.availableExercices = exercices;
this.availableExercicesChanged.next([...this.availableExercices]);
});
}
我得到的错误是:
Property 'name' does not exist on type '{}'.
Property 'duration' does not exist on type '{}'.
Property 'calories' does not exist on type '{}'.
此外,我无法构建 angular 应用程序的生产版本 ng build --prod
但是,如果我按原样使用文档(没有设置名称、持续时间、卡路里),我能够获取浏览器控制台,获得预期值:
> temp1.payload.doc.data()
{calories: 8, duration: 60, name: "Burpees"}
fetchAvailableExercices() {
this.db.collection('availablesExercices')
.snapshotChanges()
.pipe(map( docArray => {
return docArray.map( doc => {
console.log(doc);
return(
doc
);
});
}))
.subscribe(exercices => {
this.availableExercices = exercices;
this.availableExercicesChanged.next([...this.availableExercices]);
});
}
预期行为
- 以下错误
Property 'name' does not exist on type '{}'.
必须消失。
- 构建产品必须成功
PS: AngularFire: 5.0.0-rc.8 不会抛出错误消息 Property 'name' does not exist on type '{}'.
。然而,它无法构建 angular 应用程序的生产版本。
ng build --prod
Date: 2018-06-10T20:10:08.203Z
Hash: 3395c915a85b5198ef71
Time: 4427ms
chunk {0} runtime.a66f828dca56eeb90e02.js (runtime) 1.05 kB [entry] [rendered]
chunk {1} styles.d651e93934b267387a12.css (styles) 56.5 kB [initial] [rendered]
chunk {2} polyfills.cdf87a8e5b31fe8a11f1.js (polyfills) 130 bytes [initial] [rendered]
chunk {3} main.a2bc6cab25d0aa41c17a.js (main) 128 bytes [initial] [rendered]
ERROR in Error during template compile of 'AppModule'
Function calls are not supported in decorators but 'AngularFireModule' was called.
我对您项目中的 angularfire2 和 firebase 的版本有一些疑问。
这就是我为使事情正常进行所做的工作:
npm i angularfire2@5.0.0-rc.10 --save
npm i firebase@5.0.4 --save
在您的 data.service.ts
中:键入 db.collection()
呼叫
fetchAvailableExercices() {
this.db.collection<IExercice>('availablesExercices') // <== This line
.snapshotChanges()
.pipe(map( docArray => {
return docArray.map( doc => {
console.log(doc);
return(
{
id: doc.payload.doc.id,
name: doc.payload.doc.data().name,
duration: doc.payload.doc.data().duration,
calories: doc.payload.doc.data().calories,
}
);
});
}))
.subscribe(exercices => {
this.availableExercices = exercices;
this.availableExercicesChanged.next([...this.availableExercices]);
});
}
您的 app.module
中还有两句评论:
- 您应该导入 AngularFirestoreModule(已注释掉)
- 此处无需提供
AngularFireStore
属性 错误消失了,构建工作正常。
Working example here
使用新版本的AngularFire,代码变为:
fetchAvailableExercices() {
this.db.collection('availablesExercices')
.snapshotChanges()
.pipe(map( docArray => {
return docArray.map( doc => {
console.log(doc);
return(
{
id: doc.payload.doc.id,
name: doc.payload.doc.data()['name'],
duration: doc.payload.doc.data()['duration'],
calories: doc.payload.doc.data()['calories'],
}
//doc
);
});
}))
.subscribe(exercices => {
this.availableExercices = exercices;
this.availableExercicesChanged.next([...this.availableExercices]);
});
}
构建产品应用程序会很简单。
版本信息
Angular:6.0.4
Firebase: 5.0.3
Angular火:5.0.0-rc.10
ng-test-angular6@0.0.0 /home/amine/docker-projects/ng-test-angular6
├── @angular-devkit/build-angular@0.6.8
├── @angular/animations@6.0.4
├── @angular/cli@6.0.8
├── @angular/common@6.0.4
├── @angular/compiler@6.0.4
├── @angular/compiler-cli@6.0.4
├── @angular/core@6.0.4
├── @angular/forms@6.0.4
├── @angular/http@6.0.4
├── @angular/language-service@6.0.4
├── @angular/platform-browser@6.0.4
├── @angular/platform-browser-dynamic@6.0.4
├── @angular/router@6.0.4
├── @types/jasmine@2.8.8
├── @types/jasminewd2@2.0.3
├── @types/node@8.9.5
├── angularfire2@5.0.0-rc.10
├── codelyzer@4.2.1
├── core-js@2.5.7
├── firebase@5.0.3
├── jasmine-core@2.99.1
├── jasmine-spec-reporter@4.2.1
├── karma@2.0.2
├── karma-chrome-launcher@2.2.0
├── karma-coverage-istanbul-reporter@2.0.1
├── karma-jasmine@1.1.2
├── karma-jasmine-html-reporter@0.2.2
├── protractor@5.3.2
├── rxjs@6.2.0
├── ts-node@5.0.1
├── tslint@5.9.1
├── typescript@2.7.2
└── zone.js@0.8.26
如何重现这些条件
看看the angular project ng-angular6-angularfire5.0.0-rc.10
只需克隆、安装和服务。
调试输出
问题出在该行中的函数 L20
fetchAvailableExercices() {
this.db.collection('availablesExercices')
.snapshotChanges()
.pipe(map( docArray => {
return docArray.map( doc => {
console.log(doc);
return(
{
id: doc.payload.doc.id,
name: doc.payload.doc.data().name,
duration: doc.payload.doc.data().duration,
calories: doc.payload.doc.data().calories,
}
//doc
);
});
}))
.subscribe(exercices => {
this.availableExercices = exercices;
this.availableExercicesChanged.next([...this.availableExercices]);
});
}
我得到的错误是:
Property 'name' does not exist on type '{}'.
Property 'duration' does not exist on type '{}'.
Property 'calories' does not exist on type '{}'.
此外,我无法构建 angular 应用程序的生产版本 ng build --prod
但是,如果我按原样使用文档(没有设置名称、持续时间、卡路里),我能够获取浏览器控制台,获得预期值:
> temp1.payload.doc.data()
{calories: 8, duration: 60, name: "Burpees"}
fetchAvailableExercices() {
this.db.collection('availablesExercices')
.snapshotChanges()
.pipe(map( docArray => {
return docArray.map( doc => {
console.log(doc);
return(
doc
);
});
}))
.subscribe(exercices => {
this.availableExercices = exercices;
this.availableExercicesChanged.next([...this.availableExercices]);
});
}
预期行为
- 以下错误
Property 'name' does not exist on type '{}'.
必须消失。 - 构建产品必须成功
PS: AngularFire: 5.0.0-rc.8 不会抛出错误消息 Property 'name' does not exist on type '{}'.
。然而,它无法构建 angular 应用程序的生产版本。
ng build --prod
Date: 2018-06-10T20:10:08.203Z
Hash: 3395c915a85b5198ef71
Time: 4427ms
chunk {0} runtime.a66f828dca56eeb90e02.js (runtime) 1.05 kB [entry] [rendered]
chunk {1} styles.d651e93934b267387a12.css (styles) 56.5 kB [initial] [rendered]
chunk {2} polyfills.cdf87a8e5b31fe8a11f1.js (polyfills) 130 bytes [initial] [rendered]
chunk {3} main.a2bc6cab25d0aa41c17a.js (main) 128 bytes [initial] [rendered]
ERROR in Error during template compile of 'AppModule'
Function calls are not supported in decorators but 'AngularFireModule' was called.
我对您项目中的 angularfire2 和 firebase 的版本有一些疑问。
这就是我为使事情正常进行所做的工作:
npm i angularfire2@5.0.0-rc.10 --save
npm i firebase@5.0.4 --save
在您的 data.service.ts
中:键入 db.collection()
呼叫
fetchAvailableExercices() {
this.db.collection<IExercice>('availablesExercices') // <== This line
.snapshotChanges()
.pipe(map( docArray => {
return docArray.map( doc => {
console.log(doc);
return(
{
id: doc.payload.doc.id,
name: doc.payload.doc.data().name,
duration: doc.payload.doc.data().duration,
calories: doc.payload.doc.data().calories,
}
);
});
}))
.subscribe(exercices => {
this.availableExercices = exercices;
this.availableExercicesChanged.next([...this.availableExercices]);
});
}
您的 app.module
中还有两句评论:
- 您应该导入 AngularFirestoreModule(已注释掉)
- 此处无需提供
AngularFireStore
属性 错误消失了,构建工作正常。 Working example here
使用新版本的AngularFire,代码变为:
fetchAvailableExercices() {
this.db.collection('availablesExercices')
.snapshotChanges()
.pipe(map( docArray => {
return docArray.map( doc => {
console.log(doc);
return(
{
id: doc.payload.doc.id,
name: doc.payload.doc.data()['name'],
duration: doc.payload.doc.data()['duration'],
calories: doc.payload.doc.data()['calories'],
}
//doc
);
});
}))
.subscribe(exercices => {
this.availableExercices = exercices;
this.availableExercicesChanged.next([...this.availableExercices]);
});
}
构建产品应用程序会很简单。