There is a factory that receives a link and returns (should) data
(function () { angular .module('app.formBuilder') .factory('formDataService', ['$resource', function($resource) { return { data: undefined, /** * get data for form from server * @param url route with form data * @returns {json} JSON */ getFromDataFromUrl: function (url) { this.data = $resource(url, {}, { method: 'GET' }).get(); return this.data; } } }]); })(); In the controller I get it and pass it on to the directive and so on, how to make the directive and so on not write that the variable does not exist, but wait for a response, and how to get data from $ resource when I do console.log in the Osprey directive shows that vm empty, the answer comes after 2 seconds, and already after that data from the server appears in vm
(function () { 'use strict'; angular .module('app.formBuilder') .controller('FormBuilderCtrl', FormBuilderController); FormBuilderController.$inject = ['$state', 'formDataService']; function FormBuilderController($state, formDataService) { var vm = this, formJsonUrl = $state.$current.initialize, formData = formDataService.getFromDataFromUrl(formJsonUrl); formData.$promise.then(function (response) { formData = response; }); console.log(formData); vm.filterFormData = formData.filter || {}; } })();