【发布时间】:2018-07-02 11:24:28
【问题描述】:
我从我的 MongoDB 后端获取数据,数据显示在浏览器控制台中。我设法使用.但不会以 Angular 形式显示。我不知道我应该使用哪种格式。我尝试了很多格式,但都不起作用。
我需要在表单中显示itemName 和itemType。请帮我。
这是 Component.ts 文件:
import { NgModule,Component,Pipe,OnInit,OnChanges,SimpleChanges} from '@angular/core';
import { ItemAllocationService } from '../../../services/item-allocation.service'
@Component({
selector: 'app-allocation',
templateUrl: './allocation.component.html'
})
export class AllocationComponent implements OnInit {
constructor(public itemallocationservice:ItemAllocationService) { }
itemId:Number;
itemName:String;
userId:Number;
userName:String;
ngOnInit() {
}
saveallocationdata(){
const allocateitem = {
itemId:this.itemId,
itemName:this.itemName,
userId:this.userId,
userName:this.userName
};
this.itemallocationservice.itemallocationdata(allocateitem).subscribe(res=>{
console.log(res);
});
}
public x;
getItem(){
let x =this.itemallocationservice.getItemData(this.itemId).subscribe(data=>{
console.log(data);
})
}
}
HTML 文件:
<form name="reportitem" (ngSubmit)="saveallocationdata()">
<ba-card>
<div class="form-group">
<label>Item ID</label>
<input type="text" class="form-control" (keyup)="getItem()" [(ngModel)]="itemId" name="itemId">
</div>
<div class="form-group">
<label f>Item Name</label>
<input type="text" class="form-control" [(ngModel)]="itemName" name="itemName">
</div>
<div class="form-group">
<label>Enter the User Details to Allocate the Above Item</label>
</div>
<div class="form-group">
<label>User ID</label>
<input type="text" class="form-control" [(ngModel)]="userId" name="userId">
</div>
<div class="form-group">
<label>User Name</label>
<input type="text" class="form-control" [(ngModel)]="userName" name="userName">
</div>
<button type="submit" class="btn btn-primary">Allocate</button>
</ba-card>
</form>
【问题讨论】:
标签: angularjs angular angular2-forms angular4-forms