0

How do I push the value of input to tasks.name and include a default status: false to the $scope.tasks array?

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()
};

}]);

2 Answers 2

2

just push it as an object to an tasks array

$scope.updateTasks = function() {
    $scope.tasks.push({  
      name: $scope.typeTask,
      status: false
    })
};
Sign up to request clarification or add additional context in comments.

Comments

2
$scope.updateTasks = function() {
    $scope.tasks.push({name:$scope.typeTask, status: false})
};

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.