与express的angular2路由

我正在使用ng2 alpha 42版本

我的代码如下:

问题是我期望我的输出中只有一个数据,所以我不需要在我的jade.code中使用(ng-for),但是我们可以看到意外的结果,我该如何改变这一点,请帮助!

expression(它在我在PostMan中检查API时起作用)

router.get('/project/:id', function(req,res){ sql = "SELECT * FROM Projects WHERE id=" + "'" + req.params.id + "'"; db.query(sql,function(err,project){ if(err){ res.send(err); }else{ res.json(project) console.log(project) } }) }) 

ng2代码(不工作)

 export class Project{ id: string; project: string; constructor(public routeParams : RouteParams, http:Http){ //this.projects = []; this.id = routeParams.get('id') http.get('/api/projects/project/' + this.id) .map(res => res.json()) .subscribe( project => this.project = project ) } } 

玉代码(模板引擎)

 li(*ng-for="#a of project") h1 {{ a.title}} h1 {{ a.author}} h1 {{project}} 

结果:

 first topic author1 [object Object] 

我预计玉的代码是:

 h1 {{ project.title}} h2 {{ project.author}} 

但如果我把这个,我的控制台有一个错误:

 EXCEPTION: TypeError: Cannot read property 'title' of undefined in [null] 

解决这个问题

在expression中,这只会回忆一个数据

 res.json(project[0]) 

在ng2中,我忘记了声明项目types

 this.project = {}; 

这工作。 如果你能给我任何build议,我会感激。