Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Alexander Alegre
14,340 PointsAngularJS split()
Hello all, i am a little stuck on an AngularJS function Inside my controller i have:
$scope.numWords = function(str) { var wordCount = str.split(",").length; return wordCount; }
Then i call that function and i pass in $scope.userInput and it gives me an error that says "TypeError: Cannot read property 'split' of undefined"
If i do var wordCount = 'one, two, three'; I get an expected result of 3.
Can anyone tell me if I'm missing something on here?
Thanks in advance!
1 Answer
Seth Kroger
56,416 PointsI'd say the issue isn't with the $scope.numWords function itself, but when you're calling it you aren't passing the proper value. We'd need to see that part of the code the find the problem.