duanpan3166 2017-06-10 02:02
浏览 88

如何使用angular.php文件中的函数

I want to retrieve users info by a function in PHP in my angular.

angular code:

$scope.users = $http({
  method: 'GET',
   url: 'functions.php/getUsers()'
  }).then(function(response){
   $scope.users = response.data;
  },function(reason){
   $scope.error = reason.data;
  });
}

where getUsers() is the function which is returning json data to the angular.

is there any other way to use functions in angular from a PHP files?

  • 写回答

2条回答 默认 最新

  • dragon8837 2017-06-10 02:12
    关注

    remember the functions can not be equal to our public variable, in this sample you have $scope.users as function and also you have that again equal to response.data (actually you miss the function)

    you can't read from files, you have to use api URL which return json to you

    $scope.users = $http({
      method: 'GET',
       url: 'functions.php/getUsers()'
      }).then(function(response){
       $scope.users = response.data;
      },function(reason){
       $scope.error = reason.data;
      });
    }
    

    change to

    $scope.getUsers = function(){
      //for example api url for your users is "http://localhost:8080/users"
      var api = "you api url";
      $http({method: 'GET', url: api}).then(function(response){
       $scope.users = response.data;
      },function(reason){
       $scope.error = reason.data;
      });
     }    
    }
    //request data
    $scope.getUsers();
    

    OR use it directly without function

    //for example api url for your users is "http://localhost:8080/users"
    var api = "you api url";
    $http({method: 'GET', url: api}).then(function(response){
      $scope.users = response.data;
    },function(reason){
      $scope.error = reason.data;
    });
    } 
    
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?