How To Put Line Number In Source Code After Parse In HTML Page?
I am using angular js and mongoDB, In mongoDB I have some text with \n, So each line comes into the new line based on \n, But I am also want to add line number for each line. HTML
Solution 1:
it will be helpful to you
var app=angular.module('myapp',[]);
app.controller("myctrl",function($scope){
$scope.sorceText="ANB+IO:UI+OPO++7866:1111222'\OKP+JJJJ+PP++IOOIO:9989+KKKKKK+II+22:33'\nIIOI+IOIOOI+OOOO:13:1:IA+AA346+4'\nMSG+8'\nLLL+PLPL:MLML+52519950'\nNBK+290818:0000+MJL+LKL+OK+91'\nKWNN+250'\nNFR'\nKK+KK:MMM'"
$scope.sorceText_arr=[];
var arr=$scope.sorceText.split("\n");
$scope.sorceText_arr=arr;
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="myapp" ng-controller="myctrl">
<div ng-repeat="i in sorceText_arr">
<div>{{$index+1}} - {{i}}</div>
</div>
</div>
Solution 2:
Use ol
In js split to array this string.
$scope.items=$scope.sorceText.split('\n');
In html use loop on this array:
<ol>
<li ng-repeat="item in items">{{item}}</li>
</ol>
Post a Comment for "How To Put Line Number In Source Code After Parse In HTML Page?"