Reputation: 179
I'm creating Cordova plugin for Ionic 2. I receive datas from Android, and show it in console or Alert, but I'm not able to show it on html view.
device: any[] = [];
constructor(public navCtrl: NavController,
private appService: AppService) {
}
ngOnInit(): void {
devices_activity.devicesActivity(this.success, this.failure);
}
success(aL) {
for (var i = aL.length - 1; i >= 0; i--) {
aL[i];
console.log('name: ' + aL[i]);
}
}
failure() {
alert("Error calling Devices Stone SDK Plugin");
}
I tried to put aL
in device
array, but I got an error: ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'device' of null
How can I show the items received from Android in html View?
Upvotes: 0
Views: 115
Reputation: 1043
I think you device
variable is out of scope inside success
function. Try to use this. I think this should resolve your issue.
device: any[] = [];
constructor(public navCtrl: NavController,
private appService: AppService) {
}
ngOnInit(): void {
var scope = this;
devices_activity.devicesActivity((aL: any) => {
scope.device = aL;
}, () => {
alert("Error calling Devices Stone SDK Plugin");
});
}
Upvotes: 1