1

I need to get the length of Angular model $scope. My code alerts undefined.
But scope has a value when I alert scope without length

alert($scope.comppostal.length)

How to check the length? Content of $scope.comppostal is 12345

3
  • Can you post content of $scope.comppostal? Commented May 7, 2015 at 12:19
  • its working when i errase the value and re-enter Commented May 7, 2015 at 12:21
  • @Ervikas. Thats a number. How can you use .length for a number? Commented May 7, 2015 at 12:23

1 Answer 1

7

You are getting the undefined as $scope.comppostal is a number. You need to convert it to string.

Use

alert((''+$scope.comppostal).length)

var a = 12345;
alert(('' + a).length);

Sign up to request clarification or add additional context in comments.

2 Comments

is this ' ' effect on my length
@Ervikas, '' is empty string, hence no impact

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.