当我尝试从我的dataFile服务调用函数saveDataFile时,我收到错误TypeError: dataFile.saveDataFile is not a function
。(有趣的是)。
dataFile服务代码在下面,它有点奇怪,因为loadDataFile函数被调用并且没有问题。
angular.module('crmApp').
factory('data', function($http, $filter, $q){
var data = {};
data.data;
// Get the data from the DB
data.getData = function () {
var d = $q.defer();
if (data.data) {
console.log("There's already data");
d.resolve(data.data);
// console.log(data.data);
// return data.data;
}
else {
console.log("there's no data, asking for it");
return $http({
method: 'GET',
url: '/getAllData'})
.then(function(response) {
data.data = response.data;
d.resolve(data.data);
// return data.data;
},
function myError(response) {
console.log(response);
return 1;
});
}
return d.promise;
}
我从 - controller.addTasks调用的地方就在这里:
'use strict';
angular.
module('addTask')
.controller("addTask", ["$scope", "dataFile",
function($scope, dataFile) {
$scope.addTask = function(dataFile, group) {
// create the tasks json
var newTaskCreated = (new Date).getTime();
var newTask = { "task" : $scope.newTaskDescription,
"created" : newTaskCreated,
"group" : group,
"today" : false,
"status" : "incomplete"};
$scope.tasks.push(newTask);
console.log($scope.tasks);
// Save the new data in tasksData.json
dataFile.saveDataFile($scope.tasks);
// add the task to the screen
// reset the blank addtask input box
$scope.newTaskDescription = "";
}
}]);
我见过的所有类似帖子都没有帮助,所以我们非常感谢您提供的任何帮助。