1
我正在使用Angularjs和firebase创建一个应用程序,它是一个任务计时器。我创建了firebase对象,并且除了当我尝试将task.newTask
登录到控制台时,所有工作都正常。这里有一点我的代码(请注意,这不是所有的代码):输入错误:无法读取undefined的值'name'
//HTML
<aside id="sidebar">
<section id="widget_1">
<h2 class="titles">Task History:</h2>
<input id="text-field" type="text" ng-model="taskText" />
<input id="task-button" type="button" value="Add Task" ng-click="addTask()" />
</section>
<section id="widget_2">
<h2 class="titles">Task List:</h2>
<table>
<tr ng-repeat="task in timer_tasks | orderBy: '-taskText'">
<td>{{ task.taskText }}</td>
</tr>
</table>
</section>
</aside>
//Controller:
(function() {
'use strict'
function HomeCtrl($scope, $firebaseArray, $interval) {
console.log('I see you home controller ... you are loaded sir!!!')
var timerRef = firebase.database().ref().child('timer_tasks');
$scope.timer_tasks = $firebaseArray(timerRef);
$scope.addTask = function() {
$scope.timer_tasks.$add({
taskText: $scope.taskText,
newTask: true
}).then(function (timerRef) {
$scope.taskText = '';
});
};
console.log(task.newTask);
在页面加载错误在console.log(task.newTask);
任何帮助大作将是巨大的。提前致谢!
这里正确的错误信息是“任务未定义”...谢谢! –
'task'没有在控制器中定义,您在ng-repeat中使用的元素不会自动绑定到控制器。您可以使用ng-select或ng-click等。 –
我在添加任务按钮上使用ng-click =“addTask()”。那是错的吗?还是不够?如果这不起作用,我应该在哪里使用ng-click? Thx –