I am working on a directive that needs information to work. This information must come from a promise. The problem is that the directive loads without the information because the promise takes more time to execute than the directive itself. Then my code:
angular.module('app').directive('tagInput', tagInput);
var tagInput = function ($timeout, profileService) {
var profileList = profileService.getProfileList();
profileList.then(function (profiles) {
var profileObject = {};
var profilesFiltered = [];
for(var index in profiles){
if(profiles[index].hasOwnProperty('id')){
var notStandard = profiles[index].id.match(/\d+/g);
if (notStandard != null) {
profileObject.icon = '<i class="fa fa-bookmark" aria-hidden="true"></i>';
}
else{
profileObject.icon = '<i class="fa fa-user" aria-hidden="true"></i>';
}
profileObject.name = profiles[index].name;
profileObject.identifier = profiles[index].id;
profileObject.ticked = false;
profilesFiltered.push(profileObject);
}
}
return profilesFiltered;
});
return {
restrict: 'EA',
require: 'ngModel',
scope: {
tags: '=ngModel',
searchParams: '=searchParams'
},
replace: false,
link: function ( scope, element, attrs ) {
scope.modelFilter = {
showSearchPanel: false,
inputProfiles: profilesFiltered,
}
...
}
This way the data in the template always appear null. How can I prepare the data before executing the link
in the directive. You may need something very similar for inputAccounts: accountsFiltered,
.