未捕获的TypeError:angular.lowercase不是函数

Sud*_*ere 23 javascript angularjs bower angular-sanitizer

未捕获的TypeError:angular.lowercase不是函数

我的angularjs应用程序中出现此错误,并且整个应用程序未运行.这是它的表现textAngular-sanitize.js:413.

无法调试,我尝试使用与angular.js相同的版本,但没有成功.请为我提供解决方案.我没有任何东西可以在控制台中与此错误消息分享.

textAngular-sanitize.js:413 Uncaught TypeError: angular.lowercase is not a function
        at parseEndTag (textAngular-sanitize.js:413)
        at htmlParser (textAngular-sanitize.js:378)
        at textAngular-sanitize.js:147
        at textAngularSetup.js:443
        at Object.invoke (angular.js:5093)
        at angular.js:4892
        at forEach (angular.js:374)
        at createInjector (angular.js:4892)
        at doBootstrap (angular.js:1923)
        at bootstrap (angular.js:1944)
Run Code Online (Sandbox Code Playgroud)

Ovi*_*lha 27

正如你在这里看到的,angular弃用了他们的lowercaseutil方法.

您使用的库尚未更新,因此仅与1.6.7之前的角度版本兼容.但是,由于您收到此错误,您使用的角度版本可能更高.

你也可以

(A)在你的bower.json中将角度降低到1.6.7:

"dependencies": {
   "angular": "1.6.7",
   ...
}
"resolutions": {
   "angular": "1.6.7"
}
Run Code Online (Sandbox Code Playgroud)

(B)通过添加这些方法创建一个简单的解决方法:

angular.lowercase = text => text.toLowerCase();
Run Code Online (Sandbox Code Playgroud)

确保在加载角度之后但在应用程序启动之前完成此操作.

  • 我使用 `angular.lowercase = text => (text || '').toLowerCase();` 来防止 `null` 和 `undefined` 值 (2认同)

小智 8

Angular 1.7。*仍然具有小写功能,但已重命名为$$ lowercase。这是一个可能的解决方法。买家要谨防Angular文档

angular.module('MyApp').config(function() {
  angular.lowercase = angular.$$lowercase;  
});
Run Code Online (Sandbox Code Playgroud)


Sud*_*ere 5

我想分享我的观点,以便它可以帮助像我一样苦苦挣扎的其他人,主要问题是 angularJS 从他们的库中正式删除了小写和大写函数,因此使用 textAngular-sanitize.js 的人会收到此错误,因为 textangular在它的库中仍然有这个方法可以解决这个问题。

您可以从项目中删除 textAngular-sanitize.js,也可以在 angular.module 加载之前在 app.js 中包含Ovidiu Dolha代码,如下所示。

angular.uppercase=function(text){
 return text.toUpperCase();
 }
 angular.lowercase=function(text){
 return text.toLowerCase();
 }

angular.module('sampleApp', ....)
Run Code Online (Sandbox Code Playgroud)

Ovidiu Dolha 给出的代码

angular.lowercase = text => text.toLowerCase();
Run Code Online (Sandbox Code Playgroud)

可以写成

angular.lowercase=function(text){
     return text.toLowerCase();
     }
Run Code Online (Sandbox Code Playgroud)

两者都会起作用。谢谢你。