Angular 在5中绑定一个对象
当我要将数据绑定到全局变量时,我要做的就是从WebApi获取数据,并获取Undfind 这是我的订阅Angular 在5中绑定一个对象,angular,Angular,当我要将数据绑定到全局变量时,我要做的就是从WebApi获取数据,并获取Undfind 这是我的订阅 export class OverallSummaryGaugeComponent implements OnInit { gaugeVal: any; bfd; pb: ProductionBreakDown[]; gaugeSummaryType: String; constructor(private _sampleDataService: SampleDat
export class OverallSummaryGaugeComponent implements OnInit {
gaugeVal: any;
bfd;
pb: ProductionBreakDown[];
gaugeSummaryType: String;
constructor(private _sampleDataService: SampleDataObjectService, private _dashboard: DashboardService) { }
customizeText(arg) {
return arg.valueText + ' %';
}
ngOnInit() {
this.gaugeVal = this._sampleDataService.CompletedPrasantage;
this.getallData();
}
getallData() {
this._dashboard.getProductionBreakDownByDate()
.subscribe(pb => this.pb = pb
);
console.log(this.pb);
}
}
当我像这样更改代码时,它的打印数据
this._dashboard.getProductionBreakDownByDate()
.subscribe(pb => console.log(pb)
);
console.log(this.bd);
}
但我试图将其绑定到与未定义列表相同的类型
这是我的可观察代码
@Injectable()
export class DashboardService extends BaseService {
private _getProductionBreakDown = UrlsConfig.ptsapi + 'productionBreakDown/filterByDate/2018-12-17';
constructor(private _dataAccessService: DataAccessService) {
super(_dataAccessService);
}
// getting ProductionBreakDown Data
getProductionBreakDownByDate(): Observable<ProductionBreakDown[]> {
return this._dataAccessService.get<ProductionBreakDown[]>(this._getProductionBreakDown);
}
}
使用Http检索数据是一种异步操作。所以它是这样的:
getallData() {
this._dashboard.getProductionBreakDownByDate()
.subscribe(pb => {
this.pb = pb;
console.log(this.pb); //<-- both lines are now within the subscribe function
});
1) ngOnInit调用该服务,该服务向服务器发送get请求
2) 服务代码返回一个可观察的
3) 执行组件中订阅之后的任何代码
此步骤意味着在步骤5中返回数据之前,将执行下面的控制台.log
这确保绑定仅在pb
有值时导航到pb
的targetBagQuantity属性
此外,您还需要包括在订阅中检索数据后要执行的所有代码。。。所以像这样:
getallData() {
this._dashboard.getProductionBreakDownByDate()
.subscribe(pb => {
this.pb = pb;
console.log(this.pb); //<-- both lines are now within the subscribe function
});
getallData(){
此.\u dashboard.getProductionBreakDownByDate()的
.订阅(pb=>{
这是1.pb=pb;
console.log(this.pb);//使用Http检索数据是一种异步操作。因此如下所示:
getallData() {
this._dashboard.getProductionBreakDownByDate()
.subscribe(pb => {
this.pb = pb;
console.log(this.pb); //<-- both lines are now within the subscribe function
});
1) ngOnInit调用该服务,该服务向服务器发送get请求
2) 服务代码返回一个可观察的
3) 执行组件中订阅之后的任何代码
此步骤意味着在步骤5中返回数据之前,将执行下面的控制台.log
这确保绑定仅在pb
有值时导航到pb
的targetBagQuantity属性
此外,您还需要包括在subscribe中检索数据后要执行的所有代码……如下所示:
getallData() {
this._dashboard.getProductionBreakDownByDate()
.subscribe(pb => {
this.pb = pb;
console.log(this.pb); //<-- both lines are now within the subscribe function
});
getallData(){
此.\u dashboard.getProductionBreakDownByDate()的
.订阅(pb=>{
这是1.pb=pb;
console.log(this.pb);//请在此处添加完整方法,当前代码显示一些语法错误OK Wait I will addCode is added.您有解决方案吗请在此处添加完整方法,当前代码显示一些语法错误OK Wait I will addCode is added.您有解决方案吗?您是教我如何从pluralsight编写角度代码的人。谢谢。我已经看了您的演示ll pluralsight中的角度视频。酷!我在这里详细介绍:时间代码:3:44你是教我如何从pluralsight中编码角度视频的人。谢谢。我在pluralsight中看过你所有的角度视频。酷!我在这里详细介绍:时间代码:3:44