Sole
Sole

Reputation: 3340

How to count characters in UI-Angular and Bootstrap

I have a app built with Angular and Angular UI. I am trying to count the characters across multiple accordions, as displayed in the plunker. The code I have only returns the first two characters and then nothing?

Is there something wrong I am doing?

The plunk is: Example code

app.js

$scope.what=[];
$scope.why=[];

Object.defineProperty($scope, 'characters', {
    get() {
        return $scope.what.length + $scope.why.length;
    }
});

HTML:

{{characters}} 

But like I said this only returns the first two characters?

Upvotes: 0

Views: 102

Answers (2)

Thierry
Thierry

Reputation: 5243

why and what are arrays, if you want to count all the characters in these arrays, try :

Object.defineProperty($scope, 'characters', {
        get() {
            return $scope.what.join('').length + $scope.why.join('').length;
        }
});

Upvotes: 1

TheLimeTrees
TheLimeTrees

Reputation: 411

You could write up a function with a for loop to count the index of what and why and then place that in the AngularJS.

Upvotes: 0

Related Questions