[英]How to count characters in UI-Angular and Bootstrap
我有一個使用Angular和Angular UI構建的應用程序。 我正在嘗試計算多個手風琴中的字符,如插入器中所示。 我的代碼僅返回前兩個字符,然后什么也沒有?
我在做錯什么嗎?
麻煩的是: 示例代碼
app.js
$scope.what=[];
$scope.why=[];
Object.defineProperty($scope, 'characters', {
get() {
return $scope.what.length + $scope.why.length;
}
});
HTML:
{{characters}}
但是就像我說的那樣,這僅返回前兩個字符嗎?
為什么和什么是數組,如果要計算這些數組中的所有字符,請嘗試:
Object.defineProperty($scope, 'characters', {
get() {
return $scope.what.join('').length + $scope.why.join('').length;
}
});
您可以使用for循環編寫一個函數,以計算what
和why
的索引,然后將其放置在AngularJS中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.