简体   繁体   中英

AngularJS-How can I format a string containing a series of numbers to display as a list on my HTML table?

I have an HTML table that I am dynamically filling out using a couple textboxes. What I would like to do is the following:

Let

$scope.submittedNumbers = 00251212 00254545 00257878 00256565

Display as

00251212

00254545

00257878

00256565

Here is my AngularJS function that adds a row to my HTML table. How can I accomplish this?

$scope.addCertificate = function () {

    var certificate = {
        emailAddress: $scope.emailAddress,
        certificateType: $scope.certificateType,
        searchType: $scope.searchType,
        submittedNumbers: $scope.submittedNumbers,
    };

    $scope.requests.push(certificate);
};

you can split it to array in controller:

$scope.numbersAsList = $scope.submittedNumbers.split(' ');

and after iterate over it with ng-repeat:

<ul>
    <li ng-repeat="number in numbersAsList">{{ number }}</li>
</ul>

after that you can join it again with:

var joinedAgain = $scope.numbersAsList.join(' ');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM