0

Here's my json :

[
    {
        "name": "1QQQJohnQQQ11_12_1998",
        "age" : "ads"
    },
    {
        "name": "2QQQEvaQQQ05_11_1989",
        "age" : "ads"
    },
    {
        "name": "3QQQCasperQQQ12_06_1994",
        "age" : "ads"
    },
    {
        "name": "4QQQBeanQQQ30_12_1996",
        "age" : "ads"
    }]

and 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 had to split name from json by "QQQ" in javascript file. In console.log(namesplit) i have everything ("type", "date", "name") listed good.

What i need to do is write "type", "date", and "name" in table. I tried this :

 <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>

But it didn't work. Someone help? Thanks in advance.

2
  • 2
    Namesplit is not a $scope variable, hence it only exists in your promise. Commented Dec 27, 2016 at 18:58
  • @Noppey Do you have any idea how to split json "name" in javascript file? Commented Dec 27, 2016 at 19:03

1 Answer 1

2

Change all the occurrences of namesplit to $scope.namesplit in your controller.

Otherwise here, ng-repeat="name in namesplit", there is no scope variable called namesplit

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.