javascript 未捕获的类型错误:angular.lowercase 不是函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50448326/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 09:07:43  来源:igfitidea点击:

Uncaught TypeError: angular.lowercase is not a function

javascriptangularjsbowerangular-sanitizer

提问by Sudarshan Kalebere

Uncaught TypeError: angular.lowercase is not a function

未捕获的类型错误:angular.lowercase 不是函数

this error in my angularjs application, and entire application is not running. This is its showing in textAngular-sanitize.js:413.

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

Not able to debug, i tried using same version as of angular.js, but no success. Please provide me solution for this. I dont have anything to share apart from this error message in console.

无法调试,我尝试使用与 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)

回答by Ovidiu Dolha

As you can see here, angular deprecated their lowercaseutil method.

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

The library you use has not updated yet and is therefore only compatible with an angular version before 1.6.7. But since you get this error, the angular version you use is probably higher.

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

You can either

你可以

(A) Downgrade angular to 1.6.7, in your bower.json:

(A) 在你的 bower.json 中将 angular 降级到 1.6.7:

"dependencies": {
   "angular": "1.6.7",
   ...
}
"resolutions": {
   "angular": "1.6.7"
}

(B) Create a simple workaround by adding these methods back as such:

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

angular.lowercase = text => text.toLowerCase();

Make sure this is done after angular is loaded but before your app starts.

确保这是在加载 angular 之后但在您的应用程序启动之前完成的。

回答by Arthur Yegiazaryan

Angular 1.7.* still has lowercase function but it's renamed to $$lowercase. This is a possible workaround. Buyer beware based on Angular documentation.

Angular 1.7.* 仍然具有小写功能,但它已重命名为 $$lowercase。这是一种可能的解决方法。买家注意基于 Angular 文档

angular.module('MyApp').config(function() {
  angular.lowercase = angular.$$lowercase;  
});

回答by Sudarshan Kalebere

I would like to share my views so that it will help other people who are struggling like me, the main problem is angularJS officially removed lowercase and uppercase functions from their library so people who are using textAngular-sanitize.js will get this error because textangular still has this method in its library which will through this issue.

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

You can either remove textAngular-sanitize.js from your project or you can include Ovidiu Dolhacode in you app.js before angular.module loads as below.

您可以从项目中删除 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', ....)

The code given by Ovidiu Dolha

Ovidiu Dolha 给出的代码

angular.lowercase = text => text.toLowerCase();

Can be written as

可以写成

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

Both will work. Thank you.

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

回答by Matt McCann

Ovidiu Dolha's answer got me almost there. If you look at the pre-deprecation implementation of the lowercasefunction, it is a bit more. This shim implementation did the trick for me:

Ovidiu Dolha 的回答让我几乎到了那里。如果看一下lowercase函数的 pre-deprecation 实现,就有点多了。这个 shim 实现对我有用:

/**
 * @brief Shim for textAngular in order to make it compatible with the latest 
 *   version of angularjs
 */

function lowercase(string) {
  return (typeof string === 'string') ? string.toLowerCase() : string;
}

// Angular deprecated the lowercase function as of v1.6.7. TextAngular hasn't 
// updated to reflect this
angular.lowercase = lowercase;

回答by Lunin Roman

Another appropriate solution would be replace textAngularwith testAngularJsas suggestedhere.

另一种适当的解决方案将取代textAngulartestAngularJs作为建议在这里。

npm install textangularjs

npm install textangularjs

回答by Achilles Moraites

I found a similar issue when updated to angular 1.7.5 , my solution was to update angular-sanitize and the problem was fixed. angular-sanitize

我在更新到 angular 1.7.5 时发现了一个类似的问题,我的解决方案是更新 angular-sanitize 并且问题得到了解决。 角度消毒

回答by Tapash

I am using AngularJS v1.7.5. In my controller, I have used below code to convert a string into lowercase:

我正在使用AngularJS v1.7.5。在我的控制器中,我使用以下代码将字符串转换为小写:

function myCtrl($scope, $filter)
{
    var sampleText = "THIS IS TEST";
    var test = $filter('lowercase')(sampleText);
}

Inject $filterin the controller and use the same to convert to lowercase.

在控制器中注入$filter并使用相同的转换为小写。

回答by Gullfaxi171

if you are using angularjs with typescript and a linter (in my case, tslint + standard), a correct workaround would be :

如果您将 angularjs 与 typescript 和 linter(在我的情况下,tslint + 标准)一起使用,正确的解决方法是:

if (!angular.lowercase) (angular as any).lowercase = (text: string) => angular.isString(text) ? text.toLowerCase() : text