0

I'am not able to find the mistake. my php file returning data like ["9963648941","7416527247"], and i'am using angular factory to get the data using http call as below

app.factory("States", function ($http){
    var mData = {
        getStates: function(){
            return $http.get('php/usersList.php')
        }
    };
    return mData;
});

The States factory is using in the controller as follows

 app.controller('orderFormController', function($scope,$location,$rootScope,$http,States)
{
    States.getStates.then(function(response){
        console.log(JOSN.parse(response.data));
    })
});

Finally i'am getting error as States.getStates.then is not a function in the controller.

2
  • console.log(JOSN.parse(response.data)); its 'JSON.parse' Commented Feb 7, 2017 at 4:30
  • Not your current problem but Angular by default will parse JSON in the response.data property. You do not need to do it again Commented Feb 7, 2017 at 4:40

1 Answer 1

1

Here, you call the function as:

States.getStates().then(function(response){
    console.log(JOSN.parse(response.data));
})

You missed the function call brackets.

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

3 Comments

Now change it to console.log(response.data)
@krishna if you consider this as the correct answer then mark it as such please.
Happy that it helped you.

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.