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()
};
}]);
asked May 16, 2017 at 18:11
castlenibill
4641 gold badge6 silver badges14 bronze badges
2 Answers 2
just push it as an object to an tasks array
$scope.updateTasks = function() {
$scope.tasks.push({
name: $scope.typeTask,
status: false
})
};
answered May 16, 2017 at 18:13
Sachila Ranawaka
41.6k8 gold badges62 silver badges87 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
$scope.updateTasks = function() {
$scope.tasks.push({name:$scope.typeTask, status: false})
};
answered May 16, 2017 at 18:14
d9ngle
1,4893 gold badges15 silver badges30 bronze badges
Comments
lang-js