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

问题描述

我想忒一个变量传递给工厂矿井,但即时通讯不太清楚如何做到这一点,这是我的code:

I would like te pass a variable to a factory of mine, but im not quite sure how to do it, here is my code:

var app = angular.module('docFinder', []);

app.factory('docFactory', function($http) {
  var url = 'http://test.example.com?queryString=searchv2&page='; 
  url=url+page;
  var docFactory = {
    async: function() {
      var promise = $http.get(url).then(function (response) {
        return response.data;
      });
      return promise;
    }
  };
  return docFactory;
});

app.controller('docTable', function(docFactory, $scope, $filter) {

    docFactory.async().then(function(d) {   
        $scope.providers = d;       
        init();
    });

}

我想从我的控制器页面发送到我的工厂,因此它可以回到我的新查询

i would like to send the page from my controller to my factory so it can return my new query

感谢

推荐答案

您可以通过在你的工厂通过异步函数的值:

You can pass the value through your async function in your factory:

var docFactory = {
    async: function(theVarThatIWantedToPass) {
        var url=//   stuff
        url += theVarThatIWantedToPass;
    }
}

称为正常:
    docFactory.async(页)

Called as normal: docFactory.async(page)

这篇关于传递变量厂angularjs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 06:54