【问题标题】:angular js ui-route not working after minify angular appangular js ui-route在缩小角度应用程序后不起作用
【发布时间】:2017-09-18 15:21:19
【问题描述】:

您好,我使用 Angular 制作了应用程序,我使用 ui-router 进行路由,我使用 gulp-uglify 缩小了整个 Angular 应用程序。

缩小应用程序后,我的ui-router的子路由(嵌套路由)没有渲染视图,主要的父路由工作正常。

有人可以建议我在这里做什么是我的路线示例:

.state('masterPage', {
  url: "",
  abstract: true,
  templateUrl: 'src/app/Client/common/fullPage.html'
}).state('masterPage.userProfile.dashboard', {
  url: "/dashboard",
  templateUrl: "src/app/Client/userProfile/dashboard/index.html",
  controller: "userDashboard",
  controllerAs: 'vm'
})

【问题讨论】:

  • 您检查控制台是否有错误?
  • 请显示控制器userDashboard的定义。这通常是因为注入的依赖项在 min 进程中被破坏了。在此处查看隐式注释下的警告:docs.angularjs.org/guide/di
  • 控制台没有错误

标签: javascript angularjs angular-ui-router


【解决方案1】:

当您缩小应用程序时,它会破坏依赖注入。缩小 $scope 后不再是 $scope,它们是缩小的变量,如 e 或 a。这对 angularJS 没有任何意义。要解决此问题,您可以将 ng-annotate 用于需要使用 /* @ngInject */

进行自动依赖注入的 gulp 和 grunt 以及注释功能

通过此链接了解有关它的更多详细信息。 AngularJs Minification and Annotation

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-13
    • 1970-01-01
    • 2016-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-17
    • 1970-01-01
    • 2022-10-13
    相关资源
    最近更新 更多