【发布时间】:2017-04-21 11:51:43
【问题描述】:
这是我的服务
export class LunchService {
private db: any;
lunches: any = [];
constructor(
private serverService: ServerService,
private configService: ConfigService,
) {
this.db = new PouchDB(configService.config.dbServer + '/' + configService.config.dbName);
this.db.find({
selector: { 'type': 'lunch' },
}).then((result) => {
// HERE
this.lunches = result.docs;
}).catch(function(err) {
console.log(err);
});
}
}
这是我的组件
export class ListingComponent {
lunches: any = [];
constructor(
private lunchService: LunchService
) {
// IS EMPTY WHEN SET IN SERVICE?
this.lunches = this.lunchService.lunches;
}
}
为什么午餐服务中对变量的更改没有反映在组件中?控制器中的午餐参数不会被填充。
我猜它不在变化检测中?但是如何做到这一点呢?
【问题讨论】:
标签: angular2-services pouchdb angular2-components