简体   繁体   English

错误:[ng:areq]参数'fn'不是一个函数,得到了对象

[英]Error: [ng:areq] Argument 'fn' is not a function, got Object

Versions: 版本:

  • angular v1.6.4 角度v1.6.4
  • ui-router v0.3.2 ui路由器v0.3.2

I am in the process of converting a large angular application to be built using webpack. 我正在转换要使用webpack构建的大型角度应用程序。 Since I setup the build process I'm getting this error repeated multiple times in my Chrome developer console. 由于我设置了构建过程,因此我在Chrome开发者控制台中多次重复出现此错误。

Error: [ng:areq] Argument 'fn' is not a function, got Object

I have found that when I comment out the entire resolve section (where ui route states are being setup) from the code block below I get no errors but my application views don't fire off and hence my app does not work. 我发现,当我从下面的代码块中注释掉整个解析部分(正在设置ui路由状态)时,我没有收到任何错误,但是我的应用程序视图没有启动,因此我的应用程序无法正常工作。 For context this code is inside a function which is added as a config block to the main angular application module. 对于上下文,此代码位于函数内部,该函数作为config块添加到主要的角度应用程序模块中。

$stateProvider.state('productCart', {
    url: '/productCart',
    resolve: {
        initProductCartService: [
            '$state', '$q', 'constants', 'ProductCartService', 'ConfigService', 'StateService',
            function($state, $q, constants, ProductCartService, ConfigService, StateService) {
                var isReadOnlyMode = StateService.isReadOnlyMode;
                var isBypassProductCart = constants.systemProperties.IsBypassShoppingCart;
                var productCartState = constants.systemProperties.productCartState;

                return ProductCartService.getProductCartItems(true).then(function(productCartLineItems) {
                    if(!(angular.isArray(productCartLineItems) && productCartLineItems.length > 0) && !isReadOnlyMode || isBypassProductCart){
                    $state.go('catalog');

                } else {
                    return ConfigService.getProductCartPageUrl().then(function(pageUrl) {
                        if (pageUrl != null) {
                            window.location = pageUrl;
                            //handles first time returning from VF page scenario
                            window.setTimeout(function(){window.location = pageUrl}, 1000);
                            return $q.reject();
                        } else if (productCartState != null && productCartState == 'productcart') {
                            $state.go('productcart');

                        }
                    });
                }
            });
        }
    ]
},
views: {
    'header@': {
        template: require('./views/header-global.html')
    },
    'selector@productCart': {
        template: require('./views/selector-summary.html')
    },
    'cNotification@productCart': {
        template: require('./views/c-notification.html')
    },
    'recommendedProducts@productCart': {
        template: require('./views/recommended-products.html')
    },
    'processIcon@': {
        template: require('./views/process-icon.html')
    },
    'notification@': {
        template: require('./views/notification.html')
    },
    'actions@': {
        template: require('./views/actions.html')
    },
    'layout@': {
        template: require('./views/layout.html')
    },
    'layoutSingle@productCart': {
        template: require('./views/product-cart.html')
    }
},
onEnter: [
    'ConstraintRulesService',
    function (ConstraintRulesService) {
        ConstraintRulesService.setContext(0, [0]);
    }
]
});

I have come across multiple questions regarding similar errors but their issue/solution does not seem to be the same as mine. 我遇到了有关类似错误的多个问题,但它们的问题/解决方案似乎与我的不同。 I have looked into some documentation regarding the stateProvider and it appears I have the resolve section defined correctly as far as I can tell. 我查看了一些有关stateProvider的文档,据我所知,似乎我已正确定义了resolve部分。 Please let me know if you need me to provide more pieces of the puzzle just keep in mind this is a large angular app. 如果需要我提供更多的拼图,请记住,这是一个大角度的应用程序。

NOTE: I did upgrade the version of ui-router to v0.3.2 when converting to webpack since when I attempted to install the older version I using npm I would get the following error. 注意:转换为webpack时,确实将ui-router的版本升级到v0.3.2,因为当我尝试使用npm安装旧版本时,会出现以下错误。

angular-ui-router@0.2.15 invalid

I added the following event listener for state provider errors. 我为状态提供程序错误添加了以下事件侦听器。

angular.module('myModule').run( function($rootScope) {
    $rootScope.$on('$stateChangeError', function (event, toState, toParams, fromState, fromParams, error) {
        debugger
    });
});

I got the following from the toState and fromState arguments. 我从toStatefromState参数中获得了以下内容。 I'm not sure if it provides any clues. 我不确定它是否提供任何线索。 I omitted the views' template contents due to large amounts of HTML which takes away from what I'm trying to illustrate. 我省略了视图的模板内容,因为大量的HTML内容与我要说明的内容相去甚远。 The event argument does not appear to contain anything of value that I can see, toParams is an empty object, fromParams is an empty object and error param simply contains the error I posted in the title of this question. event参数似乎没有包含我可以看到的任何值, toParams是一个空对象, fromParams是一个空对象,并且error参数仅包含我在此问题的标题中发布的错误。

toState = {
    "url": "/productCart",
    "resolve": {
    "initProductCartService": [
        "$state",
        "$q",
        "constants",
        "ProductCartService",
        "ConfigService",
        "StateService",
        null
    ]
},
    "views": {
    "header@": {
        "template": "HEADER TEMPLATE CONTENT",
            "resolveAs": "$resolve"
    }
},
    "onEnter": [
    "ConstraintRulesService",
    null
],
    "name": "productCart"
}

fromState =     {
    "name": "",
    "url": "^",
    "views": null,
    "abstract": true
}

I downgrade ui-router to 0.2.15 (it installed in spite of the invalid warning/error) and continue to get this error. 我将ui-router降级为0.2.15(尽管警告/错误无效,仍将其安装),并继续出现此错误。

This is not directly related to a ui-route issue in my case. 在我的情况下,这与ui路由问题没有直接关系。 While angular was bootstrapping one of my services it was getting an "Object" instead of a function which it was expecting. 当angular启动我的一项服务时,它得到的是“对象”而不是它期望的功能。 The part I struggled with was understanding which service was the culprit (this app has hundreds of services making it difficult to just simply go through each service one by one). 我苦苦挣扎的部分是了解哪种服务才是罪魁祸首(此应用程序具有数百种服务,因此很难仅简单地逐个浏览每个服务)。 In order to determine the culprit I switched to the non-minified version of angular then used chrome developer tools "Sources" tab and checked the "Pause On Caught Exceptions" checkbox. 为了确定罪魁祸首,我切换到了angular的非最小版本,然后使用了chrome开发人员工具的“ Sources”选项卡,并选中了“ Pause On Caught Exceptions”复选框。 At first you may pick up other exceptions unrelated to your app so you may need to F8 a few times (or more) till you see your error in red colored font. 刚开始时,您可能会拾取与您的应用程序无关的其他异常,因此您可能需要几次(或多次)F8直到看到红色字体错误为止。 Looking at the stack trace on the right hand side I was able to start from the last stack and work my way up the stack till I came across a location in the angular library with a "serviceName" variable that actually indicated the service which it was failing to instantiate. 查看右侧的堆栈轨迹,我能够从最后一个堆栈开始,一直向上移动,直到遇到带有“ serviceName”变量的角度库中的某个位置,该变量实际上指示了该服务是无法实例化。 I was also able to locate a "cache" variable in the angular library (an array of instantiated modules) and noticed my service in this array. 我还能够在角度库(实例化模块的数组)中找到“缓存”变量,并在该数组中注意到了我的服务。 Looking at other services in the array they were of type function while the faulty service showed as having a type of "Object" (ah ha!). 查看阵列中的其他服务,它们是类型函数,而错误的服务则显示为“对象”类型(啊哈!)。 This service was not following the proper service format and therefore angular was unable to instantiate it. 该服务未遵循正确的服务格式,因此angular无法实例化它。 While this is completely my fault if it wasn't too much trouble it would be awesome if the angular library would include the name of the failing module in the error message. 虽然这不是完全麻烦,但这完全是我的错,但是如果角度库在错误消息中包含发生故障的模块的名称,那将是非常棒的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 (AngularJS)ng:areq错误参数:参数'fn'不是一个函数,得到对象了吗? - (AngularJS) ng:areq Bad Argument: Argument 'fn' is not a function, got Object? 参数'fn'不是一个函数,得到了对象angularjs [ng:areq] - Argument 'fn' is not a function, got Object angularjs [ng:areq] angularjs [ng:areq]参数'fn'不是函数,控制台出现字符串错误 - angularjs [ng:areq] Argument 'fn' is not a function, got string in console error 未捕获错误:[ng:areq]参数'fn'不是函数,未定义 - Uncaught Error: [ng:areq] Argument 'fn' is not a function, got undefined AngularJs:错误:[ng:areq]参数'fn'不是一个函数,未定义 - AngularJs: Error: [ng:areq] Argument 'fn' is not a function, got undefined AngularJS-错误:[ng:areq]参数'fn'不是一个函数,得到了字符串 - AngularJS - Error: [ng:areq] Argument 'fn' is not a function, got string angular.js:13424错误:[ng:areq]参数'fn'不是一个函数,得到了对象 - angular.js:13424 Error: [ng:areq] Argument 'fn' is not a function, got Object Angular“angular.js:14110错误:[ng:areq]参数'fn'不是函数,未定义”控制器实例化异常 - Angular “angular.js:14110 Error: [ng:areq] Argument 'fn' is not a function, got undefined” exception on controller instantiation 错误:[ng:areq]参数'fn'不是一个函数,未定义(Angular服务的问题) - Error: [ng:areq] Argument 'fn' is not a function, got undefined (problems with Angular service) $ routeProvider配置路由抛出“未捕获错误:[ng:areq]参数'fn'不是函数,得到了字符串” - $routeProvider config route throwing 'Uncaught Error: [ng:areq] Argument 'fn' is not a function, got string'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM