I'm trying to add a date that defaults to the current day to my page. Below is the angular script for this but when I click add day I get error of undefined? I don't understand I believe it's been defined correctly.
$scope.today= new Date();
$scope.add = {};
if($scope.today){
var today= new Date($scope.today)
$scope.add.today=
today.getFullYear()+'-'+(today.getMonth() + 1)+'-'+today.getDate();
}else{
$scope.add.today= null;
}
<div class="form-group col-sm-4">
<label for="Date">Date</label>
<input type="date" class="form-control" name="add_row_today" id="add_row_today" ng-model="today">
</div>
This is what my code looks like.
this is the stack trace from console
TypeError: Cannot set property 'today' of undefined
at m.$scope.add_list (angularScripts.js?v=1.3:8741)
at fn (eval at compile (_bower.js?v=1.2:10467), <anonymous>:4:220)
at b (_bower.js?v=1.2:10360)
at e (_bower.js?v=1.2:10510)
at m.$eval (_bower.js?v=1.2:10379)
at m.$apply (_bower.js?v=1.2:10380)
at HTMLInputElement.<anonymous> (_bower.js?v=1.2:10510)
at HTMLInputElement.dispatch (_bower.js?v=1.2:5201)
at HTMLInputElement.elemData.handle (_bower.js?v=1.2:5009)
$scope.add.today = [...]. You are trying to set the propertytodayon an object$scope.addthat has not been defined. Please explain what you're trying to do with that line of code.$scope.addas an empty object that has no propertytoday. What you should do instead is$scope.add = { today: null };