something similar to
http://jsbin.com/rifob/1/edit?js,output
On Friday, November 14, 2014 2:16:18 PM UTC, John Chacko wrote:
>
>
> Joberto Diniz ,
>
> my sample is not really working as its breaking reference to array
>
> for show/hide loading there can be a notification service.
>
> i am a newbie trying to figure out best practice. :)
>
>
> On Friday, November 14, 2014 2:08:59 PM UTC, Joberto Diniz wrote:
>>
>> But you did that. DataFactory is handling model and controller is only
>> linking it to the view.
>> I prefer model services to always return promises, so I can show loading
>> messages...
>>
>>
>> On Friday, November 14, 2014 12:04:20 PM UTC-2, John Chacko wrote:
>>>
>>> Joberto Diniz , thanks for your response
>>>
>>> I know that works. But I was trying to follow a recommendation in those
>>> blogs and avoid handling Model in controllers.
>>> my intention was to make a sample as per those blog.
>>>
>>>
>>>
>>> On Friday, November 14, 2014 12:47:49 PM UTC, Joberto Diniz wrote:
>>>>
>>>> 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.