$scope.AddTask = function () {
$scope.tasks.push([{
"taskName": $scope.taskName,
"priorty": $scope.selectedP
}]);
};
$scope.tasks = [{
"taskId": 1,
"taskName": "task 1",
"priorty": 1
}, {
"taskId": 2,
"taskName": "task 2",
"priorty": 2
}, {
"taskId": 3,
"taskName": "task 3",
"priorty": 3
}];
我收到了一个无法读取属性的错误' push'在angularjs中未定义
app demo:http://plnkr.co/edit/ObKoQn2tZ4evgJpKQBpH?p=preview
答案 0 :(得分:3)
$scope.tasks.push({
"taskName" : $scope.taskName,
"priorty": $scope.selectedP
});
而不是额外的[]
。
答案 1 :(得分:1)
见此功能:
$scope.AddTask = function() {
$scope.tasks.push([{
"taskName": $scope.taskName,
"priorty": $scope.selectedP
}]);
};
您必须在[]
{}
之前删除$scope.tasks.push
,他们要在$scope.tasks
内推送另一个数组,他们必须推送{{1}}的对象强>