我有一个本地放大器设置,我试图将有角度的$ log消息推送到txt文件。但我不断收到javaScript错误。这是错误
angular.js:9101 TypeError: $scope.todos.push is not a function
这是我的代码:
angular.module('Todo', []).factory('myhttpserv', function($http) {
return $http.get('storage.txt').error(function(status) {
console.log(status)
});
}).controller('TodoController', function($scope, myhttpserv, $http) {
$scope.appTitle = "MyTodoList",
myhttpserv.then(function(response) {
$scope.todos = (response.data !== null) ? response.data : [];
var httpPost = function() {
$http.post('save.php', JSON.stringify($scope.todos)).error(function(status) {
console.log(status)
});
};
$scope.addTodo = function() {
$scope.todos.push({
text: $scope.todoText,
doneProd: false,
doneDev: false
});
$scope.todoText = ''; //clear the input after adding
httpPost();
};
$scope.remaining = function() {
var count = 0;
angular.forEach($scope.todos, function(todo) {
count += todo.doneProd && todo.doneDev ? 0 : 1;
});
return count;
};
$scope.archive = function() {
var rusure = confirm("Are you sure you want to remove the completed tasks from the list?");
if (rusure) {
var oldTodos = $scope.todos;
$scope.todos = [];
angular.forEach(oldTodos, function(todo) {
if (!todo.doneProd || !todo.doneDev)
$scope.todos.push(todo);
});
httpPost();
}
};
$scope.delete = function(idx) {
var rusure = confirm("Are you sure you want to remove the task from the list?");
if (rusure) {
$scope.todos.splice(idx, 1);
httpPost();
}
};
$scope.edit = function(idx) {
var changes = prompt("Please make the changes below", $scope.todos[idx].text);
if (changes != null) {
$scope.todos[idx].text = changes;
httpPost();
}
};
$scope.checkboxClick = function() {
httpPost();
};
$('.splash, .container').fadeToggle();
});
});

<div class="splash">
<h2>Loading</h2>
</div>
<div class="container">
<header class="app-header">
<h1 class="app-title" data-ng-bind="appTitle"></h1>
</header>
<section class="app-body">
<table>
<thead>
<tr>
<th>
TITLE
</th>
<th></th>
<th></th>
<th class="chk">
PROD
</th>
<th class="chk">
DEV
</th>
</tr>
</thead>
<tbody>
<tr data-ng-repeat="todo in todos track by $index">
<td>
<span class="done-{{ todo.doneProd && todo.doneDev }}" data-ng-bind="todo.text"></span>
</td>
<td>
<a data-ng-click="delete($index)"><i class="fa fa-times"></i></a>
</td>
<td>
<a data-ng-click="edit($index)"><i class="fa fa-pencil-square-o"></i></a>
</td>
<td class="chk">
<input type="checkbox" data-ng-model="todo.doneProd" data-ng-change="checkboxClick()">
</td>
<td class="chk">
<input type="checkbox" data-ng-model="todo.doneDev" data-ng-change="checkboxClick()">
</td>
</tr>
</tbody>
</table>
<section class="archive-control">
<span>{{ remaining() }} of {{ todos.length }} remaining</span>
<a class="fr" href="" data-ng-click="archive()" data-ng-show="remaining() < todos.length">Remove Completed Items</a>
</section>
<form data-ng-submit="addTodo()" class="todo-form">
<input type="text" data-ng-model="todoText" placeholder="Enter new task item" />
<br />
<input type="submit" value="Add Task" />
</form>
</section>
</div>
&#13;
这是我的php文件,我的文件夹中也有我的storage.txt:
<?php
$data = file_get_contents("php://input");
$myfile = fopen("log.txt", "w") or die("Unable to open file!");
fwrite($myfile, $data);
fclose($myfile);
?>