i created a plug-in for field
angular.module('ersProfileForm').directive('ersProfileEditableField', ['$templateCache', '$compile', 'profileFieldService', 'RolesService',
function($templateCache, $compile, profileFieldService , RolesService){
return {
restrict: 'AE',
templateUrl: '',
scope: {
ersProfileEditableField: '=',
ersProfileSectionData: '=',
ersProfileEditableFieldValue: '=',
ersBulkEdit: '<'
},
controller: ['$scope', '$http','$q','$resource', function($scope, $http, $q, $resource){
$http.get('rest/roles',{}).then(function(response){
$scope.roles = response.data;
});
}],
link: function(scope, iElement, iAttrs, controller){
iElement.append(jQuery(profileFieldService.getTemplate(scope.ersProfileEditableField.type, scope)));
$compile(iElement.contents())(scope);
}
};
}]);
roles data will be used in this template
angular.module('ersProfileForm').factory('profileFieldService', ['$resource', function($resource){
var factory = {};
factory.getTemplate = function(type, scope){
scope.field = scope.ersProfileEditableField;
var tpl = '<div ng-repeat ="role in roles"'>
+' <label>{{role.name</label>'
+' </div>'
break;
return tpl;
};
return factory;
}]);
i want roles array in this template but service is taking time so roles is not defined in template it is executing after some time
my question is that i want roles data from the request only then go to template which is defined in link?
getTemplate
right after your$scope.roles
at the moment thelink
bit gets called before the data is returned from your call.