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
Get Angular scope variable length
提问by Coder
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
我需要获得 Angular 模型的长度$scope
。我的代码提醒undefined
。
但是scope
当我scope
没有提醒时有一个价值length
alert($scope.comppostal.length)
How to check the length? Content of $scope.comppostal
is 12345
如何检查长度?的内容$scope.comppostal
是12345
回答by Satpal
You are getting the undefined
as $scope.comppostal
is a number. You need to convert it to string.
你得到undefined
的$scope.comppostal
是一个数字。您需要将其转换为字符串。
Use
利用
alert((''+$scope.comppostal).length)
var a = 12345;
alert(('' + a).length);