我在 Angular JS 中有一个应用程序,我试图弄清楚如何将两个字符计数长度添加在一起(来自文本区域输入),如下所示,但这不起作用:
$scope.what=[];
$scope.why=[];
$scope.characters = $scope.what.length + $scope.why.length;
我做错了什么?
最佳答案
字符
应该是一个函数:
$scope.characters = function(){
return $scope.what.length + $scope.why.length;
}
然后在您的 HTML/ View 中调用该函数:
{{ characters() }}
您在 characters
对象将在构建时初始化并保持静态时的设置方式。
关于javascript - Angular JS 将两个输入的字符长度相加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32204714/