我们有一个旧的AngularJS应用程序,我们已经将其转换为React(因为我们不喜欢Angular的发展方向,AngularJS似乎被抛弃了,React看起来更像旧的Angular为我们工作的方式)。
我们要执行的指令之一是,一旦检测到窗口和视图内容已经完成/准备就绪,就隐藏一个启动元素,如下所示:
.directive('loadingOverlay', ['$window', '$q', '$animate', '$rootScope', '$timeout',
function($window, $q, $animate, $rootScope, $timeout) {
return {
priority: 500,
restrict: 'C',
link: function(scope, el, attrs) {
// hide the splash
function finish() {
$('#splash').remove();
}
// detect the window load has finished loading
var windowLoad = $q.defer();
$($window).on('load', function() {
windowLoad.resolve();
});
// detect the view has finished loading
var viewLoaded = $q.defer();
scope.$on('$viewContentLoaded', function() {
viewLoaded.resolve();
});
// once both have resolved, call finish
$q
.all([windowLoad.promise, viewLoaded.promise])
.then(function (results) {
$timeout(finish, 1000);
});
}
}
}
]);
React是否具有类似于$q
和$viewContentLoaded
的东西?