angularjs - Directive isn't properly updating controller variable -


i'm new angular, , i'm trying update 1 of controller's variables directive, won't seem work. variable populated in directive, , when log there it's fine. when try log variable controller; logs fine @ first, it's "undefined".

i have no idea why happening. :(

directive

app.directive('reportfilter', function() {  return {   restrict: 'e',   scope: {},  controller: 'maincontroller',  templateurl: 'js/directives/reportfilter.html', link: function(scope, element, attrs) {  scope.updatetable = function(selectedoffer,startdate,enddate) { var offer='offer:'+selectedoffer.offer_id;         $.ajax({             type: 'post',             url: 'daily_summary.php',             data: {                  'offer': selectedoffer.offer_id          },         datatype: 'json',         cache: false,         success: function(response) {           scope.myvariable=response;           scope.getdata();           console.log(scope.myvariable);           scope.$apply();           }     });     }   } } 

});

controller

  app.controller('maincontroller', ['$scope', 'service',   'offerservice','$attrs', function($scope, service,offerservice) {    $scope.getdata= function () {           console.log($scope.myvariable);           return $scope.myvariable;       };  }]); 

this console's log showing variable become undefined again in controller


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -