我正在使用MEAN Stack和Angular 6开发Web应用程序。我的架构具有以下值。 用户名:默认, ExtrudedHeight:250,
html页面中有一个按钮。单击按钮后,我要获取userName =默认值的集合的值。
为此,我在路由器中创建了一个get方法,
//通过用户名获取单个值
router.get('/:userName', function(req, res, next) {
alert(Came to router);
extrudedHeight.findOne({'userName': req.params.userName}, function (err, post) {
console.log(req.params.userName);
if (err) return next(err);
res.json(post);
});
});
service.ts
getExtrudedHeight(userName) {
return this.http.get('/extrudedHeight/' + userName, {
});
}
html
<div class="">
<button type='button' (click)="setDefaultValues()" class="btn btn-sm btn-rectangle btn-default text-case">Default Values</button>
</div>
component.ts
Class{
extrudedHeightValue = {};
ngOnInit(){
this.setDefaultValues();
}
setDefaultValues(){
this.extrudedHeightService.getExtrudedHeight("default").subscribe(data => {
console.log(data);
this.extrudedHeightValue = data;
});
}
}
我的问题是我在路由器中添加了一个警报,但是当我按下按钮时它没有显示。这是否意味着我的路由错误?