如何将输入值推送到tasks.name
并在status: false
数组中包含默认$scope.tasks
?
HTML
<input type="text" ng-model="typeTask">
<button ng-click="updateTasks()">Add task</button>
JS(AngularJS)
var app1 = angular.module('app1', []);
app1.controller('ctrl1', ['$scope', function($scope) {
$scope.typeTask = "test";
$scope.tasks = [
{
name: 'Example task 1',
status: false
},
{
name: 'Example task 2',
status: true
},
{
name: 'Example task 3',
status: false
}
];
$scope.updateTasks = function() {
$scope.tasks.push()
};
}]);
答案 0 :(得分:2)
将它作为对象推送到tasks
数组
$scope.updateTasks = function() {
$scope.tasks.push({
name: $scope.typeTask,
status: false
})
};
答案 1 :(得分:2)
$scope.updateTasks = function() {
$scope.tasks.push({name:$scope.typeTask, status: false})
};