import ngModule from '../module'; class Controller { constructor($http, $state) { this.$http = $http; this.$state = $state; } _getBotanical() { let filter = { where: {itemFk: this.$state.params.id}, include: [{relation: 'genus'}, {relation: 'specie'}] }; this.$http.get(`/item/api/ItemBotanicals?filter=${JSON.stringify(filter)}`) .then(res => { if (res.data.length) { this.botanical = res.data[0]; } else { this.botanical = { itemFk: this.$state.params.id, botanical: null, genusFk: null, specieFk: null }; } }); } $onInit() { this._getBotanical(); } } Controller.$inject = ['$http', '$state']; ngModule.component('vnItemBotanical', { template: require('./index.html'), controller: Controller });