[英]Meteor Angular2 and external changed of Mongodb
I play around with a simple Meteor Angular 2 app which only read from database. 我玩一个简单的Meteor Angular 2应用,该应用仅从数据库读取。 I have another app which change the database.
我还有另一个可以更改数据库的应用程序。 But when the database is changed, I got error on Meteor app.
但是,当数据库更改时,Meteor应用程序出现错误。
Exception in queued task: EXCEPTION: Error in client/match.html:0:19
ORIGINAL EXCEPTION: TypeError: Cannot read property 'league' of undefined
ORIGINAL STACKTRACE:
TypeError: Cannot read property 'league' of undefined
at DebugAppView._View_MatchComponent0.detectChangesInternal (MatchComponent.template.js:101:59)
at DebugAppView.AppView.detectChanges (http://localhost:3001/packages/modules.js?hash=5bea6cc36ccb7076b2a2834b250a3c141ff0cd78:57326:14)
at DebugAppView.detectChanges (http://localhost:3001/packages/modules.js?hash=5bea6cc36ccb7076b2a2834b250a3c141ff0cd78:57415:44)
at DebugAppView.AppView.detectViewChildrenChanges (http://localhost:3001/packages/modules.js?hash=5bea6cc36ccb7076b2a2834b250a3c141ff0cd78:57346:34)
at DebugAppView._View_MatchesComponent1.detectChangesInternal (MatchesComponent.template.js:106:8)
at DebugAppView.AppView.detectChanges (http://localhost:3001/packages/modules.js?hash=5bea6cc36ccb7076b2a2834b250a3c141ff0cd78:57326:14)
at DebugAppView.detectChanges (http://localhost:3001/packages/modules.js?hash=5bea6cc36ccb7076b2a2834b250a3c141ff0cd78:57415:44)
at DebugAppView.AppView.detectContentChildrenChanges (http://localhost:3001/packages/modules.js?hash=5bea6cc36ccb7076b2a2834b250a3c141ff0cd78:57341:37)
at DebugAppView._View_MatchesComponent0.detectChangesInternal (MatchesComponent.template.js:65:8)
at DebugAppView.AppView.detectChanges (http://localhost:3001/packages/modules.js?hash=5bea6cc36ccb7076b2a2834b250a3c141ff0cd78:57326:14)
ERROR CONTEXT:
[object Object]
I'm using autopublish which collection: 我正在使用自动发布哪个集合:
import {Mongo} from 'meteor/mongo';
export let MatchCollection = new Mongo.Collection('matches');
And angular component: 和角分量:
export class MatchesComponent
{
matches;
constructor() {
this.matches = MatchCollection.find();
}
}
Note: Meteor Blaze version works well. 注意:Meteor Blaze版本效果很好。 And I'm new to Meteor Angular2.
我是Meteor Angular2的新手。
Thanks for all help. 感谢您的所有帮助。
I guess you are using *ngFor
. 我猜您正在使用
*ngFor
。
You can use this more stable way 您可以使用这种更稳定的方式
this.matches = MatchCollection.find().fetch();
MatchCollection.find();
returns Mongo.Cursor<any>
; 返回
Mongo.Cursor<any>
;
MatchCollection.find().fetch();
returns Array<any>
返回
Array<any>
It looks like the external change removed a property names league
within the document, which your angular2 view uses somewhere. 外部更改似乎删除了文档中的属性名称
league
,您的angular2视图在某处使用了该属性。
Have a look at the document via meteor mongo
to see how the document looks like in the storage before and after it has been modified by the external process. 通过
meteor mongo
查看该文档,以查看该文档在被外部过程修改之前和之后在存储中的外观。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.