AngularJS Factory Parameter

半腔热情 提交于 2019-11-28 21:20:42

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");
}
Wottensprels

If i understand correctly, you want something like that:

app.factory('myFactory',function(){

  return{

    prop: '',

    setProp: function(newProp){

        this.prop = newprop;

    }
  }

});

You should watch this:

https://egghead.io/lessons/angularjs-providers

And read this:

AngularJS: Service vs provider vs factory

mcbjam

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!