I am new to Meteor and the angular2 -meteor package, and I am trying to learn how to use them according to the well-prepared tutorial for the Social app found here: Social Turikul .
During experiments with what I saw there about the Publish / Subscribe functions, I discovered a problem that I do not know how to solve. To be clear, I made a very simple project with this structure:
/typings/test.d.ts
interface Test {
_id?: string;
num: number;
}
/collections/tests.ts
export var Tests = new Mongo.Collection<Test>('tests');
/server/main.ts
import './tests';
/server/test.ts - just publishes everything
import {Tests} from 'collections/tests';
Meteor.publish('tests', function() {
return Tests.find();
});
/client/app.ts - subscribe to sort results
import {Component, View} from 'angular2/core';
import {bootstrap} from 'angular2-meteor';
import {MeteorComponent} from 'angular2-meteor';
import {Tests} from 'collections/tests';
@Component({
selector: 'app'
})
@View({
templateUrl: 'client/app.html'
})
class Socially extends MeteorComponent {
tests: Mongo.Cursor<Test>;
constructor(){
super();
this.subscribe('tests', () => {
this.tests = Tests.find({}, {sort: {num: -1}});
}, true);
}
}
bootstrap(Socially);
/client/app.html - a simple ngFor showing the results
<div>
<ul>
<li *ngFor="#test of tests">
<p>{{test._id}}</p>
<p>{{test.num}}</p>
</li>
</ul>
</div>
Mongo, . , . , , "num" , , , , :
: TypeError: l_test0 undefined [{{test._id}} Social @@: 15]
, :
id: 1 - num: 6
id: 2 - num: 5
id: 3 - num: 4
"num" 4, "num" 7, :
- id: 3 - num: 7
- id: 1 - num: 6
- id: 2 - num: 5
.
, , , , , .
.
EDIT:
/ . , mongo:
db.tests.insert({_ id: 1, num: 6})
db.tests.insert({_ id: 2, num: 5})
db.tests.insert({_ id: 3, num: 4})
db.tests.update({_ id: 3}, {$ set: {num: 7}})
:
db.tests.find()
:
{ "_id" : 1, "num" : 6}
{ "_id" : 2, "num" : 5}
{ "_id" : 3, "num" : 7}