AngularJS 工厂参数 [英] AngularJS Factory Parameter

查看:28
本文介绍了AngularJS 工厂参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向 angularjs 服务发送参数.这是我的服务代码:

I'm trying to send a parameter to an angularjs service. Here is my service code :

angular.module('skyBiometryServices', ['ngResource'])
.factory('Facedetect', function( $resource ) {
    return $resource('skyBiometry/facedetect', {}, {
        query: {
            method : 'GET',
            params : {imageUrl: "http://cdn1-public.ladmedia.fr/var/public/storage/images/dossiers/presidentielles-2012/les-news-sur-les-presidentielles-2012/exclu-public-cauet-pour-ces-presidentielles-personne-ne-me-fait-rever-209063/2064021-1-fre-FR/Exclu-Public-Cauet-Pour-ces-presidentielles-personne-ne-me-fait-rever-!_portrait_w674.jpg"},
            isArray: false
        }
    })
});

在我的控制器中,我有这个:

In my controller i have this :

function IndexCtrl($scope,Facedetect) {
    $scope.text = Facedetect.query();
}

如何将 imageurl 从控制器发送到我的服务中?像这样

How can i send the imageurl into my services from the controller ? Something like this

function IndexCtrl($scope,Facedetect) {
    $scope.text = Facedetect.query('MY IMAGE URL');
}

提前致谢.

推荐答案

通过更多的研究,我找到了一个解决方案:

With more research i found a solution :

factory('Facedetect', function( $resource ) {
    return $resource('skyBiometry/facedetect', {}, {
        query: {
            method : 'GET',
            params : {imageUrl: "http://cdn1-public.ladmedia.fr/var/public/storage/images/dossiers/presidentielles-2012/les-news-sur-les-presidentielles-2012/exclu-public-cauet-pour-ces-presidentielles-personne-ne-me-fait-rever-209063/2064021-1-fre-FR/Exclu-Public-Cauet-Pour-ces-presidentielles-personne-ne-me-fait-rever-!_portrait_w674.jpg"},
            isArray: false
        }
    })
});


function IndexCtrl( $scope, $routeParams, Facedetect ) {
    $scope.imageurl = 'http://flepi.net/images/personne-tendue.jpg';
    $scope.text = $scope.text = Facedetect.get({imageUrl: $scope.imageurl});
}

我不知道这是否是最好的方法,但它确实有效.

I don't know if it's the best way but it works.

这篇关于AngularJS 工厂参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆