我正在使用AngularJS
,并将其与webpack
捆绑在一起。为了处理我的状态,我使用了ui-router
。我已经更改了应用程序的结构,因此状态作为模式加载。当我关闭状态(模态)时,它不断出现错误消息:
TypeError:(void 0)不是一个函数
我在网上搜索过,还有其他人,但似乎没有一个能给出为什么的确切答案。如果我将功能更改为console.log消息,则不会,但不会导致该错误。当我从模式状态转到任何其他状态时,引起该问题的原因。我一直在关注这篇文章https://www.sitepoint.com/creating-stateful-modals-angularjs-angular-ui-router/。我将为代码提供状态结构和用于关闭模态的函数。
$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',
},
"[email protected]": {
templateUrl: 'app/templates/patent/patent-details.tpl.htm',
controller: 'patentDetailsCtrl',
controllerAs: '$ctrl'
},
}
}
问题
为什么关闭模式时会显示错误TypeError: (void 0) is not a function
(在关闭时导航至其他状态)?
最近我遇到了同样的错误,困扰我的原因是我将ts.config中的模块prop从'system'更改为'amd'。
https://www.typescriptlang.org/docs/handbook/modules.html
希望这会有所帮助。
Ps。我只是将其作为评论而非完整的答案,但我没有足够的声誉!