Angular.js: Error classString.split is not a function

Created on 18 Sep 2018  路  5Comments  路  Source: angular/angular.js

I'm submitting a ...

  • [X] bug report
  • [ ] feature request
  • [ ] other

Current behavior:

Log trace in the console :
TypeError: classString.split is not a function
at split (angular.js:27114)
at updateClasses (angular.js:27043)
at ngClassWatchAction (angular.js:27085)
at Scope.$digest (angular.js:18585)
at Scope.$apply (angular.js:18945)
at done (angular.js:12799)
at completeRequest (angular.js:13056)
at XMLHttpRequest.requestLoaded (angular.js:12961)
(anonymous) @ angular.js:15018
(anonymous) @ angular.js:11302
$digest @ angular.js:18603
$apply @ angular.js:18945
done @ angular.js:12799
completeRequest @ angular.js:13056
requestLoaded @ angular.js:12961
load (async)
(anonymous) @ angular.js:12944
sendReq @ angular.js:12744
serverRequest @ angular.js:12485
processQueue @ angular.js:17396
(anonymous) @ angular.js:17444
$digest @ angular.js:18557
$apply @ angular.js:18945
(anonymous) @ angular.js:28106
dispatch @ jquery-3.3.1.min.js:2
y.handle @ jquery-3.3.1.min.js:2

Expected / new behavior:

No such log trace.

Minimal reproduction of the problem with instructions:

I have no idea about what is generating the log trace. Maybe it's a misuse of the framework from me, but if so I don't know where my error is.

AngularJS version: 1.7.2

Browser: [all | Chrome XX | Firefox XX | Edge XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]

I only tested with Chrome.

Anything else:

Most helpful comment

We've had this bug for 4 years. It didn't harm anything, but by saying it was related to ng-class helped me locate which one and fix it. I feel like a million bucks!

All 5 comments

This error can happen if you are binding ng-class to an expression that does not evaluate to a string, array or object.
E.g. using a number: ng-class="42".

This is incorrect usage, but we should handle this more gracefully indeed :grin:

Thanks George, your comment helped me to find and solve the problem. I think the most important point is that you document somewhere that that error is related to ng-class, so that the developer knows what to look at.

Glad you solved it.

BTW, looking at the stack trace, it should be easy to find out that the error happens inside ngClass, because a certain variable is not a string. But determining where that string came from is more challenging, due to ngClass's internal complexity.

We've had this bug for 4 years. It didn't harm anything, but by saying it was related to ng-class helped me locate which one and fix it. I feel like a million bucks!

for me it was
ng-class="col-md-10"

when should have been
class="col-md-10"

Was this page helpful?
0 / 5 - 0 ratings