Factories.js 中的多个函数
Multiple Functions in Factories.js
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 error 的第一个数据集,但无法加载第二个数据集日志错误数据。我在底部添加了另一行 .factory('LogErrorData',LogErrorData);
然而,这打破了第一个 cad 错误,所以我删除了它。任何帮助,将不胜感激。如果您需要更多代码,我可以提供。
更新
controller.js
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;
});
}
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
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;
});
}
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 error 的第一个数据集,但无法加载第二个数据集日志错误数据。我在底部添加了另一行 .factory('LogErrorData',LogErrorData);
然而,这打破了第一个 cad 错误,所以我删除了它。任何帮助,将不胜感激。如果您需要更多代码,我可以提供。
更新
controller.js
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;
});
}
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
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;
});
}