$http or $resource data not binding in $scope function,

74 views
Skip to first unread message

mohammad naveed

unread,
Mar 8, 2014, 5:12:46 AM3/8/14
to ang...@googlegroups.com
 Owner.factory('OwnerSrvc', function($resource){
    return $resource('/owner/:id', {

            query: { method: 'GET', isArray: true },
            create: { method: 'POST' },
            show: { method: 'GET', isArray:true},
            update: { method: 'PUT', params: {id: '@id'} },
            delete: { method: 'DELETE', params: {id: '@id'} }

        }
    )
});


//my controller using $resource factory variable ownerSrvc


Owner.controller('ownerCtrl', function($scope, OwnerSrvc, $location){


    OwnerSrvc.query({id:'531784367883254406700e99'},function(data) {
      //  console.log(data[0]);        retrievig data of Mr. Ali
        $scope.owner = data[0];        binding works here at controller level;
    });




//User defined function at Congtroller level

  $scope.editUser=function(ids){  //when i called this function later with id

   OwnerSrvc.query( //params{id:ids},    //my service giving me result fine
   function(data) {

                 console.log(data[0]);                 //result showing in console OK  i.e. Mr. Zain
              $scope.owner = data;   // but data not binding with $scope.owner

          });
 
  console.log($scope.owner)  // here after Query called, $scope.owner showing old result i.e Mr. Ali instead of Mr. Zain

          $location.path('/owner');

});

// MY QUESTION IS WHY DATA NOT BINDING AT FUNCTION LEVEL INSIDE CONTROLLER AND HOW TO BIND NEW DATA WITH $scope.owner

 Either i use $resource or $http or Restangular, but data is not binding in this function

Kindly help

Ziobudda

unread,
Mar 8, 2014, 9:46:42 AM3/8/14
to ang...@googlegroups.com

Hi..

Il giorno 08/mar/2014, alle ore 11:12, mohammad naveed <naveed...@gmail.com> ha scritto:


   OwnerSrvc.query( //params{id:ids},    //my service giving me result fine
   function(data) {

                 console.log(data[0]);                 //result showing in console OK  i.e. Mr. Zain
              $scope.owner = data;   // but data not binding with $scope.owner

Hi, have you tried to add 

$scope.$apply();

after this last line ?


M.
--
Davide Morelli




mohammad naveed

unread,
Mar 8, 2014, 11:09:54 AM3/8/14
to ang...@googlegroups.com
$scope.$apply(); throwing exception


--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/o5jRoTbkNB8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages