0
我需要從Mongo DB mongoose中獲取select下拉列表vales。Angular 2從Mongoose DB填充選擇下拉值
在我的角度2,我有一些東西,是靜態的:
更新的代碼:
我想要實現這樣的事情,我已經嘗試過這樣的:
<form role="form">
<fieldset class="form-group">
<label>Select Category</label><br/><br/>
<select [(ngModel)]="selectedObject" name="first" class="form-control">
//Static data
<!--<option>Select</option>
<option>Juices</option>
<option>Chats</option>
<option>Meals</option>-->
<option *ngFor="let c of categories"
[value]="c"
[selected]="c.categoryName == selectedObject.categoryName"
>
{{c.categoryName}}
</option>
</select>
</fieldset>
</form>
在我的組件。我有類似的東西:
export class BlankPageComponent implements OnInit {
selectedObject = null;
categories = [];
constructor(private addproductService: AddproductService,
private flashMessage: FlashMessagesService,
private router: Router) { }
ngOnInit() {
const categories = {
category_name: this.category_name
}
this.addproductService.loadData(categories).subscribe(data => {
});
的\ src \程序\共享\服務\ addproduct.service.ts
export class AddproductService {
categories: any;
loadData(pList: any) {
this.categories = pList;
if (this.categories.length > 0) {
let headers = new Headers();
headers.append('Content-Type', 'application/json');
return this.http.post('http://10.22.*.*:3000/categories/get', this.categories, { headers: headers })
.map(res => res.json());
//this.selectedObject = this.categories[0];
}
}
Error as of now: TypeError: Cannot read property 'subscribe' of undefined
,但我需要從後端獲得的下降值下降(將它們綁定)
在我的貓鼬後端我有一個文件,字段名稱:category_name,其值有:Juice,Meals,Chats等,並且在郵遞員中我像使用API一樣獲取它們:
http://10.22 ..:3000/categories/get
我能夠使用GET請求, 但如何綁定選擇控制和貓鼬填充數據
由於從獲取的的NodeJS類@馬丁,我發現,但我怎麼從後端,通過API的指定我的問題 – phyme
已更新我的問題@Martin,我需要實現的東西如圖所示,但我不確定的訂閱和flatMap運算符,需要幫忙! – phyme