首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Factories.js中的多个函数

Factories.js中的多个函数
EN

Stack Overflow用户
提问于 2018-04-18 18:42:51
回答 1查看 80关注 0票数 0
代码语言:javascript
运行
复制
 function CadError($http) {

    // Return the object
    return {

        // Create simple method to get data from $http service
        getFullList : function() {
            return $http({

                url: 'URL',
                method: 'GET'
            })
        }
        
    }

}

function LogError($http) {

    // Return the object
    return {

        // Create simple method to get data from $http service
        getFullList : function() {
            return $http({
                url: 'URL',
                method: 'GET'
            })
        }
    }

    }

    angular
        .module('inspinia')
        .factory('CadError', CadError);

我想知道如何在一个factories.js文件中实现两个数据集。我能够加载第一个称为cad错误的数据集,但我无法加载第二个集日志错误数据。我在底部添加了另一行.factory('LogErrorData',LogErrorData);

然而,这打破了第一个cad错误,所以我删除了它。任何帮助都将不胜感激。如果你需要更多的代码,我可以提供。

更新

controller.js

代码语言:javascript
运行
复制
function caderror($scope, CadError) {

    // Run method getFullList() from factory
    myFac.getFullList().success(function(data){

        // Assign data to $scope
        $scope.dataFromFactory = data;
    });

}
function logerror($scope, LogError) {

    // Run method getFullList() from factory
    myFac.getFullList().success(function(data){

        // Assign data to $scope
        $scope.dataFromFactory = data;
    });

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-18 18:57:40

代码语言:javascript
运行
复制
angular
     .module('inspinia')
     .factory('myFac', function($http){
     return {
        CadError : function() {
            return {
               // Create simple method to get data from $http service
               getFullList : function() {
                   return $http({url: 'URL',method: 'GET'})
               }
              }
        },
        LogError: function() {
           return {
             getFullList : function() {
                return $http({url: 'URL',method: 'GET'})
               }
            }
         }
    }
  });

CONTROLLER.JS

代码语言:javascript
运行
复制
function caderror($scope, myFac) {

    // Run method getFullList() from factory
    myFac.CadError().getFullList().success(function(data){

        // Assign data to $scope
        $scope.dataFromFactory = data;
    });

}
function logerror($scope, myFac) {

    // Run method getFullList() from factory
    myFac.LogError().getFullList().success(function(data){

        // Assign data to $scope
        $scope.dataFromFactory = data;
    });

}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49906860

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档