我有一個從服務器檢索數據的異步函數,我有一個指令應該顯示異步函數檢索的數據。如何阻止執行指令直到指定時間?
我想要做的是在我的指令中放置一個假的ng-show,假設除非將ng-show放入true,否則指令將不會加載。 在我的異步函數檢索數據之前,ng-show將保持爲false。
事情是這是行不通的,該指令將加載,無論我是否放置一個ng顯示或不 - 其他任何想法?
這是我在代碼中曾嘗試:
JS:
getFile.then(function (result) {
$scope.show = true;
Utilities.safeApply($scope);
})
HTML:
section class="list file-list group" ng-show="show" view-mode="assets">
<file file="model.file"></file>
</section>
指令:
.directive('file', ['$rootScope', '$compile', function($rootScope, $compile) {
return {
restrict: 'E',
replace: true,
templateUrl: 'file.html',
scope: {
show: '='
},
controller: function($scope) {
//do stuff here once async function finished
}
這絕對是可行的,但在沒有查看代碼的情況下幫助你是有點困難的。請更新問題以顯示您所嘗試的內容(並且,如果可以的話,請準備好一個重擊者)。 – link
添加了一些源代碼 –