TypeError: (void 0) is not a function 在关闭模态窗口时发生

huangapple go评论142阅读模式
英文:

TypeError: (void 0) is not a function when closing modal

问题

抱歉,由于文本中包含大量代码,无法进行完整的翻译。以下是您提供的内容的摘要:

我正在使用AngularJS并与webpack一起打包。为了处理我的状态,我使用了ui-router。我已更改了我的应用程序结构,使状态作为模态加载。当我关闭状态(模态)时,它一直出现以下错误消息:

> TypeError: (void 0) is not a function

我已在网上搜索,有其他人遇到类似的问题,但似乎没有明确的答案说明原因。如果我将函数更改为打印消息,它会打印消息并且不会导致错误。当我从模态状态切换到任何其他状态时,会出现问题。我一直在遵循这篇文章:https://www.sitepoint.com/creating-stateful-modals-angularjs-angular-ui-router/。我将提供我的状态结构和关闭模态的函数代码。

(以下是您提供的部分代码)

问题:为什么在关闭模态(导航到不同状态)时会记录错误TypeError: (void 0) is not a function

请注意,由于篇幅原因,无法提供完整的代码翻译。如果您需要更多帮助或有其他问题,请随时提出。

英文:

I'm using AngularJS and bundling it with webpack. To handle my states I'm using ui-router. I've changed the structure of my application so a state loads as a modal. When I close the state (modal) it keeps coming up with the error message:

> TypeError: (void 0) is not a function

I've searched online and there are others but none that seem to give a definitive answer to why this is caused. If I change the function to console.log a message, it does and it doesn't cause that error. Somethings causing the issue when I go from the modal state to any other state. I've been following this article https://www.sitepoint.com/creating-stateful-modals-angularjs-angular-ui-router/. I'll provide the code the structure of my states and the function for closing the modal.

$stateProvider
.state('portfolio', {
    url: '/portfolio',
    templateUrl: 'app/templates/portfolio/portfolio.tpl.htm',
    controller: 'portfolioCtrl',
})
.state('portfolio.modal', {
    abstract: true,
    views: {
        "modal": {
            templateUrl: "app/templates/patent/modal.html"
        }
    },
    onEnter: ["$state", function($state) {

        $(document).on("click", ".modal-backdrop, .modal-holder", function() {

            $state.go("portfolio");
        });

    }]

})
.state('portfolio.modal.patent', {
    url: '/:patentId',
        views:{
            "": {
                templateUrl: 'app/templates/patent/case-overview.tpl.htm',
                controller: 'caseOverviewCtrl',
                controllerAs: '$ctrl',

            },
            "details@portfolio.modal.patent": {
                templateUrl: 'app/templates/patent/patent-details.tpl.htm',
                controller: 'patentDetailsCtrl',
                controllerAs: '$ctrl'      
            },
      }
 }

Question

Why is the error TypeError: (void 0) is not a function logging when I close the modal (navigate to a different state on close)?

答案1

得分: 3

最近我一直遇到相同的错误,后来发现答案是将ts.config中的模块属性从'system'更改为'amd'。

希望这能帮助你。

附言:我本来只想将这个作为评论而不是一个完整的答案,但我没有足够的声誉!

英文:

I have been getting the same error plaguing me recently and the answer turned out to be changing my module prop in ts.config from 'system' to 'amd'.

https://www.typescriptlang.org/docs/handbook/modules.html

Hope this helps.

Ps. I would have just put this as a comment rather than a full blown answer but i don't have enough reputation!

huangapple
  • 本文由 发表于 2020年1月7日 00:30:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/59615640.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定