Angular2:从http.get响应中提取数组元素
Angular2: extract array element form http.get response
Angular2 非常有趣!(讽刺结束)
这个特定的 plunker 成功地从数组中提取了一个非常特定的元素,然后能够将其显示到 templateUrl 中。一般来说,在模板中显示数据真的很容易。
不幸的是,这不是我的问题。我需要做的是从dataService/Injectable获取一个值并将其转换为变量,然后将该变量传递到图表程序中。基本上,我需要这样的东西: console.log(last);
//a simple json data component
import {Component, View} from 'angular2/angular2'
import {DataService} from './dataService'
@Component({
selector: 'my-data',
templateUrl: 'src/template.html'
})
export class Data {
constructor(dataService:DataService) {
dataService.dataObser
.subscribe(dataObj => {
this.last = dataObj.person.last;
this.dataObj = dataObj;
});
console.log("this is what I'm looking for " + this.last);
}
}
然后,我将获取变量并传递到 chartData 中,如此问题中所述。这就是为什么我需要从 json 捕获此响应并将其转换为变量。我想这应该不会那么难吗?
dataService.dataObser
.subscribe(dataObj => {
this.last = dataObj.person.last;
this.dataObj = dataObj;
});
// this line is executed before the first `dataObject` event arrives.
console.log("this is what I'm looking for " + this.last);
如果只有一个预期事件,请将此行移动到.subscribe()
回调中,否则添加complete
回调
dataService.dataObser
.subscribe(dataObj => {
this.last = dataObj.person.last;
this.dataObj = dataObj;
},
(_) => {},
() => {
console.log("this is what I'm looking for " + this.last);
});
// this line is executed before the first `dataObject` event arrives.
相关文章:
- 在函数中添加数组元素的数值
- 访问JSON对象内部的数组元素
- Mongoose-在更新中删除数组元素
- javascript数组元素是否知道其封闭数组
- 将数组元素附加到FormData dos'不适用于Firefox 15
- 如何从合并的结果集中提取数组
- 如何在javascript中使用click函数选择数组元素
- 如何在JavaScript中剥离数组元素中的非整数
- 消隐数组元素是否生成自己的属性
- 如何使一个Math.random数组元素比另一个数组元素更有可能被选中
- 在Codrops的内容中添加数组元素展开缩略图网格预览
- 如何使用Jquery水平打印表中的数组元素,并在某个元素之后垂直打印
- 如何访问数组中的数组元素(JavaScript)
- 生成ACF标记位置的数组(元素列表后缺少])
- validate.js验证数组元素
- 在Jquery中从JSON中提取数组值
- JavaScript Unshift EACH 数组元素
- Angular2:从http.get响应中提取数组元素
- 提取具有最大属性值的数组元素
- 如何提取数组的元素