Below is the JSON data I am working with:
[
{
"name": "1QQQJohnQQQ11_12_1998",
"age" : "ads"
},
{
"name": "2QQQEvaQQQ05_11_1989",
"age" : "ads"
},
{
"name": "3QQQCasperQQQ12_06_1994",
"age" : "ads"
},
{
"name": "4QQQBeanQQQ30_12_1996",
"age" : "ads"
}]
Next, here's a snippet of my JavaScript file:
var app = angular.module('app', []);
app.service('service', function($http, $q){
var deferred = $q.defer();
$http.get("datesss.json").then(function(data){
deferred.resolve(data);
});
this.getNames = function(){
return deferred.promise;
}
});
app.controller('secondCtrl', function($scope, service){
var promise = service.getNames();
promise.then(function(data){
$scope.names = data.data;
var namesplit = $scope.names
namesplit.map(function(item) {
item.type = item.name.split('QQQ')[0];
item.date = item.name.split('QQQ')[1];
item.name = item.name.split('QQQ')[2];
});
console.log(namesplit);
});
});
I needed to split the name field from the JSON by the delimiter "QQQ" in the JavaScript file. When I log namesplit
, everything seems fine.
Now, my goal is to display "type", "date", and "name" in a table. I attempted the following code:
<thead>
<tr>
<th class="text-center">type</th>
<th class="text-center">date</th>
<th class="text-center">name</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="name in namesplit">
<td>{{name.type}}</td>
<td>{{name.date}}</td>
<td>{{name.name}}</td>
</tr>
</tbody>
Unfortunately, it didn't work as expected. Can someone please provide guidance? Thank you in advance.