【问题标题】:Migrating from Angular 1.2.14 to 1.4.2 breaks whole application从 Angular 1.2.14 迁移到 1.4.2 会破坏整个应用程序
【发布时间】:2015-09-28 13:11:44
【问题描述】:

我有以下定义的角度应用程序:

var myApp = angular.module('myApp', ['ngRoute','infinite-scroll','geolocation', 'ngAnimate', 'ngTouch','ui.filters', 'AxelSoft','angularLazyImg','wu.masonry','ui.bootstrap','ngSanitize']);

到目前为止,我使用的是 AngularJS 版本 1.2.14。现在我需要使用 AngularJS 表单验证,为了做到这一点,我决定迁移到 Angular 的最新稳定版本 1.4.2

当我更改了 angular 版本时,事情就坏了,控制台抛出了

未捕获的错误:[$injector:modulerr] 带有以下堆栈跟踪:

错误:$injector:modulerr 模块错误

Failed to instantiate module myApp due to:
TypeError: Cannot read property 'push' of undefined
    at http://localhost:8000/static/mobile/js/angularApp/app.js:6:37
    at Object.e [as invoke] (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js:39:156)
    at d (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js:37:328)
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js:37:452
    at m (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js:7:322)
    at g (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js:37:229)
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js:37:398
    at m (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js:7:322)
    at g (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js:37:229)
    at eb (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js:40:503

我已经尝试阅读和理解 angularJS 官方迁移指南,但我无法弄清楚其中的内容,因为我没有在我的代码中使用 $animate(它 $animate 和 $touch 只为另一个注入可以工作的插件,即滑块,而且我也使用过“ngROute 任何地方”)

有没有人知道应该在这里做什么,因为我不知道从哪里开始:)

【问题讨论】:

  • 第 6 行有什么?在你的 app.js
  • 您的依赖项与您使用的新版本的 Angular 不兼容。转到每个第 3 方站点,然后下载适当的版本以用于 angular 1.4.2 或相应地更改您的凉亭配置。
  • 您好 Babajide,这是第 5-6 行的代码,其中我使用 HTTP 拦截器来拦截 HTTP 请求并显示加载器:--------------- -------- myApp.config(function ($httpProvider) { $httpProvider.responseInterceptors.push('myHttpInterceptor');//第6行

标签: angularjs migrate


【解决方案1】:

所以这是迁移我的 Angular 应用程序需要做的事情。

  1. 使用相同版本的angular迁移ngRoute和ngAnimate
  2. 移除 1.2 中的 HTTP 拦截器,并将其更改为 Angular 1.4 的样式

就我而言,删除 $httpProvider 并迁移 ngAnimate 和 ngRoute 解决了我的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-10
    • 2022-11-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多