After http call is successful, you need to update the *$scope.contacts*:

angular.module('myApp', [])
    .factory('DataFactory', function($http) {
        var service = {};
        service.contacts = [];
        service.searchContacts = function(searchFor) {
            return 
$http.jsonp('http://johnchacko.net/jqm/searchp.php?callback=JSON_CALLBACK&searchfor='
 
+ encodeURI(searchFor))
                .success(function(data) {
                    // magic line, we resolve the data IN the factory!
                  console.log(data.contacts);
                    service.contacts = data.contacts;
                })
                .error(function() {
                    service.contacts = [];
                });
        };

        return service;
    })
    .controller('ContactSearch', function($scope, DataFactory) {
        $scope.contacts = DataFactory.contacts;
        $scope.searchFor = '';


        $scope.search = function() {
            console.log($scope);
            DataFactory.searchContacts($scope.searchFor).then(function(){
                  $scope.contacts = DataFactory.contacts;
                });
        };

    });



On Friday, November 14, 2014 9:35:52 AM UTC-2, John Chacko wrote:
>
> this is with reference to the concept in below blogs
>
> http://toddmotto.com/rethinking-angular-js-controllers/?
>
> http://jonathancreamer.com/the-state-of-angularjs-controllers/
>
>
> where it talks about keeping Model out of Controllers and service taking 
> are of Model.
>
> I tried below sample and it seems missing array by reference, so now 
> updating results.
>
> http://jsbin.com/qeratubero/2/
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to