我有一个从服务器检索数据的异步函数,我有一个指令应该显示异步函数检索的数据。如何阻止执行指令直到指定时间?
我想要做的是在我的指令中放置一个假的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
添加了一些源代码 –