给定函数之外的angular Js调用函数

时间:2017-07-27 07:26:23

标签: angularjs function-calls

    google.maps.event.addListener(marker, 'dragend', function() {
       getmydata = function() {
            return $http.get("getConnectionData.php").then(function (response) {
                         $scope.links1 = response.data.records;
                   });

               }

              getmydata().then(function(data) {
              // stuff is now in our scope, I can alert it
              console.log("hiiiii" , $scope.links1);
              });


 });

这里我想在dragend函数之外调用此部分 - google.maps.event.addListener(marker,'dragend',function(){

getmydata().then(function(data) {
    // stuff is now in our scope, I can alert it
     console.log("hiiiii" , $scope.links1);
});

我该怎么办呢。

2 个答案:

答案 0 :(得分:1)

你可以写这样的东西

{{1}}

您现在可以在任何地方拨打电话

答案 1 :(得分:1)

您需要从$http.get电话

返回数据
 google.maps.event.addListener(marker, 'dragend', function() {
   getmydata = function() {
       return $http.get("getConnectionData.php").then(function (response) {
                 return response;
           });
       }

      getmydata().then(function(data) {
      // stuff is now in our scope, I can alert it
      $scope.links1 = data;
      console.log("hiiiii" , $scope.links1);
      });
 });