[Progress Communities] [Progress OpenEdge ABL] Forum Post: RE: Service Initialization

  • Thread starter Radoslav Kirilov
  • Start date
Status
Not open for further replies.
R

Radoslav Kirilov

Guest
Hi Louis, You do not need to build the template in the resolve of the state, since your code is not synchronous and your template will be populated in the future when the http call’s response is returned. You need to build it directly into the view and pass the data got from external call in the controller. For example: extensions/index.js 'use strict'; import angular from 'angular'; import sideNavigationTemplate from './../common/side-navigation-extended/index.html'; import sideNavigationController from './../common/side-navigation-extended/index.js'; // Import your custom modules here: export default angular.module('app.extensions.module', [ // Put your custom modules here: ]).run(['$state', '$rootScope', function($state, $rootScope) { var state = $state.get('module.default'); if (state && state.views && state.views['side-navigation']) { state.views['side-navigation'].templateUrl = sideNavigationTemplate; state.views['side-navigation'].controller = sideNavigationController; } }]).name; side-navigation-extended/index.html {{item.label}} side-navigation-extended/index.js 'use strict'; const SideNavigationCtrl = function($scope, $element, $state, $q) { var data = [ { id: 1, label: 'blankOne-extended', state: 'module.default.moduleOne.blankOne' }, { id: 2, label: 'blankTwo-extended', state: 'module.default.moduleOne.blankTwo' }, { id: 3, label: 'blankOne-second-extended', state: 'module.default.moduleTwo.blankOne' }, { id: 4, label: 'blankTwo-second-extended', state: 'module.default.moduleTwo.blankTwo' } ]; populateAditionalMenus(); function populateAditionalMenus() { getServiceData().then((data) => { $scope.data = data; }); } function getServiceData() { var deferred = $q.defer(); setTimeout(() => { deferred.resolve(data); }, 500); return deferred.promise; } }; SideNavigationCtrl.$inject = ['$scope', '$element', '$state', '$q']; export default SideNavigationCtrl Please note that in the code above I simulate http call with timeout, but on your case you need to execute similar logic in jtslibService.getMenus().then(() => { // custom logic for populating model which is bound in html }) I hope this helps. Best, Rado

Continue reading...
 
Status
Not open for further replies.
Top