javascript 获取 Angular 范围可变长度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30100917/
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-28 11:40:29  来源:igfitidea点击:

Get Angular scope variable length

javascriptangularjs

提问by Coder

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

我需要获得 Angular 模型的长度$scope。我的代码提醒undefined
但是scope当我scope没有提醒时有一个价值length

alert($scope.comppostal.length)

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

如何检查长度?的内容$scope.comppostal12345

回答by Satpal

You are getting the undefinedas $scope.comppostalis a number. You need to convert it to string.

你得到undefined$scope.comppostal是一个数字。您需要将其转换为字符串。

Use

利用

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

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