Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Error classString.split is not a function #16697

Closed
1 of 3 tasks
Cimballi opened this issue Sep 18, 2018 · 5 comments
Closed
1 of 3 tasks

Error classString.split is not a function #16697

Cimballi opened this issue Sep 18, 2018 · 5 comments

Comments

@Cimballi
Copy link

I'm submitting a ...

  • 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:

@gkalpak
Copy link
Member

gkalpak commented Sep 18, 2018

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 😁

@Cimballi
Copy link
Author

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.

@gkalpak
Copy link
Member

gkalpak commented Sep 19, 2018

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.

gkalpak added a commit to gkalpak/angular.js that referenced this issue Sep 19, 2018
Previously, when an `ngClass` expression evaluated to something that was
not a string, array or object (and was truthy), an error would be thrown
while trying to call `.split()` on a non-string value. This error was
not very helpful for the user to identify the root cause of the problem.

This commit fixes it by ensuring such values are converted to string.

Fixes angular#16697
gkalpak added a commit that referenced this issue Sep 20, 2018
Previously, when an `ngClass` expression evaluated to something that was
not a string, array or object (and was truthy), an error would be thrown
while trying to call `.split()` on a non-string value. This error was
not very helpful for the user to identify the root cause of the problem.

This commit fixes it by ensuring such values are converted to string.

Fixes #16697

Closes #16699
@ravihugo
Copy link

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!

@hope4555
Copy link

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

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants