0
我正在處理需要某些信息才能工作的指令。但是,這些信息來自諾言,並且指令加載時沒有這些信息,因爲指令本身需要更多時間。Angular在執行指令鏈接前獲取承諾數據
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,
...
這樣總是模板中的數據顯示爲空。如何在指令鏈接執行前準備數據。也許我需要類似的承諾inputAccounts: accountsFiltered,
。