Angularjs 将参数传递到$http into指令

Angularjs 将参数传递到$http into指令,angularjs,Angularjs,我使用此服务模型从DB获得推荐: .service('getComArt', function($http) { delete $http.defaults.headers.common['X-Requested-With']; this.getData = function(callbackFunc) { $http.get('http://www.domain.it/commenct.php') .success(function(da

我使用此服务模型从DB获得推荐:

.service('getComArt', function($http) {
    delete $http.defaults.headers.common['X-Requested-With'];
    this.getData = function(callbackFunc) {
        $http.get('http://www.domain.it/commenct.php')
            .success(function(data) {
                callbackFunc(data)
            })
            .error(function() {
                alert("Error!")
            })
    }
})
是否可以调用添加控制器获取的参数的服务?
例如,如果我使用相同的服务,但只提取id=xxxx的注释

如果您只想通过传递参数来获取,那么您所要做的就是连接到URL,否则如果您的方法是POST,则必须定义数据

获取:

职位:

var data = {name:'John', password : '1234'}
$http.post('http://www.domain.it/commenct.php/', data).success(successCallback);

好吧,我想解释我不好!这就是解决方案:

创建工厂以进行$http调用

.factory('getContent', function($http) {
    return function(id){
        return $http({
            method: 'GET',
            url: 'http://www.domain.it/page.php',
            params: {id:id}
         });
    }
})  
然后在控制器中:

getContent(id).success(
    function (data) {$scope.items = data}
);

您可以向getData函数添加一个附加参数,但是,您必须修改php脚本以处理按id检索单行的操作
getContent(id).success(
    function (data) {$scope.items = data}
);