AngularJS厂参数 [英] AngularJS Factory Parameter

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

问题描述

我想一个参数发送到angularjs服务。这里是我的服务,code:

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();
}

我怎么能发送图片网址进入我的服务从控制器?事情是这样的。

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');
}

在此先感谢。

推荐答案

您可以写你的工厂像这样

You can write your factory like this

app.factory('Facedetect',function($resource) {

  return {

    query: function(image_url) {
      return $resource('skyBiometry/facedetect', {}, {
             query: { method: 'GET', params: {imageUrl:image_url}, isArray: false }
      }).query();

    }
  }
});

现在在你的控制器就可以写

Now in your controller you can write

function IndexCtrl($scope, Facedetect) {
  $scope.text = Facedetect.query("YOUR/IMAGE/URL");
}

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

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