Why not work? data between views and list detail

Hi!
I read this article : http://learn.ionicframework.com/formulas/sharing-data-between-views/ and this is cool, work, but i would json array from php (its work), i modified this code (up link):

  .factory('TodosService', function($q, $http) {
    return {
    	todos: function(){
    		return $http.get('http://server/file.php').then(function(response) {
    		console.log('Success', response);
    		// For JSON responses, response.data contains the result
    		}, function(err) {
    		console.error('ERR', err);
    		// err.status will contain the status code
    		})
    		},
    	getTodos: function() {
    		return this.todos
    		},
    	getTodo: function(todoId) {
    		var dfd = $q.defer()
    		this.todos.forEach(function(todo) {
    		if (todo.pix_name === todoId) dfd.resolve(todo)
    		})
    		return dfd.promise
    		}
    }
    })

work: todos: write here json sample,
dont work: function() or todos: response.data
sorry my english…
thx

I’m sorry, but I don’t understand your problem.
I think you should take a look at Promises to completely understand what you are doing. https://docs.angularjs.org/api/ng/service/$q

1, the original code is here(thats work):

todos: [
      {
        id: '1',
        name: 'Pick up apples',
        done: false
      },
      {
        id: '2',
        name: 'Mow the lawn',
        done: true
      }
    ],

2, changed this array(thats work):
todos: [
{“pix_id”:“821”,“pix_name”:“jrojv”,“pix_date”:“2015-11-07 11:20:36”},
{“pix_id”:“820”,“pix_name”:“rbbb”,“pix_date”:“2015-11-07 00:02:10”},
{“pix_id”:“819”,“pix_name”:“djc”,“pix_date”:“2015-11-06 19:22:01”},
],

3 from server side answer same 2 (not work)

todos: function(){
    		return $http.get('http://server/file.php').then(function(response) {
    		console.log('Success', response);
    		// For JSON responses, response.data contains the result
    		}, function(err) {
    		console.error('ERR', err);
    		// err.status will contain the status code
    		})
    		},

1, 2, show the elements in view, but 3 nothing

i hope so understandable :smile:

Yep, I got that.
The problem is that $http.get() doesnt directly return the response object, it returns a promise.
I’m not very good at explaining it, but you should learn about promises and then everything will get clear.
I could post you a working solution, that wouldn’t help you in the long term though. Feel free to ask any questions. :wink:

Thanks, i find the solution :smile:

nah ok, now the code prints :smile:
{data, status, method, tranformResponse, url, headers, statusText}
not only data…

todos: $http.get('http://server.hu/list.php').success(function(data) { 
}),