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 || {}; } })(); 
  • and where is the directive? can you give an example on plunkr ? - Grundy
  • @Grundy has already decided) passed the promiss to derektiri and then executed the data binding - Khotey Vitaliy
  • then you can post your answer or close the question. In addition - the angular can rezolvit resource in view - Grundy

0