当前位置:  开发笔记 > 编程语言 > 正文

TypeError:d [h] .apply不是函数

如何解决《TypeError:d[h].apply不是函数》经验,为你挑选了1个好方法。

不知道我在这里做错了什么.基本上设置路由以在页面加载css动画时显示gif.gif出现但一切都淡出,gif停留在页面上,我收到控制台中的"TypeError:d [h] .apply不是函数"错误.任何帮助表示赞赏.这是代码:

HTML:




    
    Open Weather Map App
    
    


    


CSS:

body, html { position: relative; min-height: 100%;}
.loading {
    position: relative;
    height: 100%;
}
.loading:before {
    position: absolute;
    content: "";
    left: 0;
    bottom: 0;
    right: 0;
    top: 0;
    z-index: 1000;
    background: rgba(255, 255, 255, 0.9) no-repeat center center;
    background-image: url('./loading-animation.gif');
}
.animate-view-container { position: relative; min-height: 100%; }
.animate-view.ng-enter,
    .animate-view.ng-leave {
        transition: 1s linear all;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: #eee;
    }
.animate-view.ng-enter { opacity: 0; z-index:100; }
.animate-view.ng-enter.ng-enter-active { opacity: 1; }
.animate-view.ng-leave { opacity: 1; z-index: 99; }
.animate-view.ng-leave.ng-leave-active { opacity: 0; }

JS:

angular.module('OWMApp', ['ngRoute', 'ngAnimate'])
    .value('owmCities', ['New York', 'Dallas', 'Chicago'])
    .config(['$routeProvider', function($routeProvider){
        $routeProvider.when('/', {
            templateUrl: 'home.html',
            controller: 'HomeCtrl'
        })
        .when('/cities/:city', {
            templateUrl: 'city.html',
            controller: 'CityCtrl',
            resolve: {
                city: function(owmCities, $route, $location) {
                    var city = $route.current.params.city;
                    if(owmCities.indexOf(city) == -1){
                        $location.path('/error');
                        return;
                    }
                    return city;
                }
            }
        })
        .when('/error', {
            template: '

Error - Page Not Found

' }); }]) .controller('HomeCtrl', ['$scope', function($scope){ }]) .controller('CityCtrl', function($scope, city){ $scope.city = city; }) .run(function($rootScope, $location){ $rootScope.$on('$routeChangeError', function(){ $loaction.path('/error'); }); $rootScope.$on('$routeChangeStart', function(){ $rootScope.isLoading = true; }); $rootScope.$on('$routeChangeSuccess', ['$timeout', function(){ $timeout(function(){ $rootScope.isLoading = false; }, 1000); }]); });

小智.. 5

错误在这里:

$rootScope.$on('$routeChangeSuccess', ['$timeout', function(){
    $timeout(function(){
        $rootScope.isLoading = false;
    }, 1000);
}]);

只需删除数组,$timeout只留下函数作为第二个参数$on.

$rootScope.$on('$routeChangeSuccess', function(){ ...

应该在这里完成依赖注入(和其他deps一样):

.run(function($rootScope, $location, $timeout){ ...

相关文档:https://docs.angularjs.org/api/ng/type/$rootScope.Scope



1> 小智..:

错误在这里:

$rootScope.$on('$routeChangeSuccess', ['$timeout', function(){
    $timeout(function(){
        $rootScope.isLoading = false;
    }, 1000);
}]);

只需删除数组,$timeout只留下函数作为第二个参数$on.

$rootScope.$on('$routeChangeSuccess', function(){ ...

应该在这里完成依赖注入(和其他deps一样):

.run(function($rootScope, $location, $timeout){ ...

相关文档:https://docs.angularjs.org/api/ng/type/$rootScope.Scope

推荐阅读
Gbom2402851125
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有