【发布时间】:2019-07-23 17:49:15
【问题描述】:
我需要为 REST API 下载的数据安装可视化,但在通过打字稿进行动态制作时出错。 数据正确地来自服务器。
<FlexboxLayout
flexWrap="wrap"
#flex
>
</FlexboxLayout>
在打字稿上:
import { FlexboxLayout } from 'tns-core-modules/ui/layouts/flexbox-layout/flexbox-layout';
import { StackLayout } from 'tns-core-modules/ui/layouts/stack-layout';
import { Image } from 'tns-core-modules/ui/image';
import { Label } from 'tns-core-modules/ui/label';
// ...
@ViewChild('flex',{static: false}) flex: FlexboxLayout;
ngOnInit() {
// Populate the categories variable with server data
categories.forEach((cat) => {
this.createCategView(cat);
});
}
createCategView(c: Category) {
let stack = new StackLayout();
let img = new Image();
img.src = c.image;
img.stretch = "none";
img.width = 25;
img.height = 25;
let label = new Label();
label.text = c.name;
stack.addChild(img);
stack.addChild(label);
this.flex.addChild( stack );
}
但是最后一条命令行返回一个错误,指出 this.flex.addChild 方法不是函数。
【问题讨论】:
标签: angular typescript nativescript angular2-nativescript