ionic3 - ERROR Error: Uncaught (in promise): Error: InvalidPipeArgument: #39;[object Object]#39; for pipe #39;AsyncPipe#39;(ionic3 - 错误错误:未捕获(承诺):错误:InvalidPipeArgument:[object Object] for pipeAsyncPipe)
问题描述
在测试评论功能已经工作之后,我用 ionic3 用 firebase 做了一个新闻评论功能,但是当我想在我的项目中显示评论时出现错误.
I did a news comment function by ionic3 with firebase, after testing comment function working already, but when I want the comment showing in my project error coming out.
错误错误:未捕获(承诺):错误:InvalidPipeArgument:管道AsyncPipe"的[object Object]"
ERROR Error: Uncaught (in promise): Error: InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe'
我的项目遵循此教程.
html 文件
<ion-list>
<ion-item-group *ngFor="let contact of contactsList | async">
<ion-item>
{{contact.$value}}
</ion-item>
</ion-item-group>
</ion-list>
<ion-list>
<ion-row>
<ion-col col-6>
<ion-input type="text" [(ngModel)]="Contact" placeholder="写评论..."></ion-input>
</ion-col>
<ion-col>
<button ion-button color="primary" (click)="addContact()">发布</button>
</ion-col>
</ion-row>
</ion-list>
ts 文件
import { AngularFireList } from 'angularfire2/database';
export class NewsDetailPage {
new: any;
contactsList:AngularFireList<any>;
Contact = '';
constructor(public navCtrl: NavController, public navParams: NavParams,
private qq: QQSDK, private socialSharing: SocialSharing,
public firebaseService:FirebaseServiceProvider,public alertCtrl: AlertController
// private photoViewer: PhotoViewer
) {
this.new = navParams.get('new');
this.contactsList = this.firebaseService.getContactsList();
}
addContact() {
this.firebaseService.addContact(this.Contact);
const alert = this.alertCtrl.create({
title: '评论成功!',
//subTitle: 'Your friend, Obi wan Kenobi, just accepted your friend request!',
buttons: ['确认']
});
}
更新:
getContactsList() {
return this.angularfiredb.list('/contactsList/');
}
推荐答案
你需要先将 AngularFireList 转换为 Observable:
You need to first convert the AngularFireList to an Observable :
contactsList: Observable<any[]>;
在你的构造函数中,你需要调用 valueChanges()
.这是从 AngularFire2 版本 5 开始的.
And in your constructor, you need to call valueChanges()
on it. This is since AngularFire2 Version 5.
this.contactsList = this.firebaseService.getContactsList().valueChanges();
这将通过不带 $key
或 $value
的 observable 返回数据.为了在 html 中打印,请使用
This will return the data through the observable without $key
or $value
.
In order to print in html,use
{{contact}}
而不是
{{contact.$value}}
这篇关于ionic3 - 错误错误:未捕获(承诺):错误:InvalidPipeArgument:'[object Object]' for pipe'AsyncPipe'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:ionic3 - 错误错误:未捕获(承诺):错误:InvalidPipeArgument:'[object Object]' for pipe'AsyncPipe'
基础教程推荐
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01