3
I have studied programming Frond-End and I took several tips from friends on Angularjs and refer me some demo sites of Angularjs, at the moment I am trying to implement Datepicker and I am not having result.
CLICK HERE FOR YOU TO SEE THE DEMONSTRATION OF ANGULARJS
Above you can see the implementation and also the lines of code, in fact I did the way it is on the site, and it looks exactly like it is on the site but does not work, see below;
<html ng-app="datepickerBasicUsage">
<html>
<head>
<title>Calendário</title>
<style>
HTMLJSCSS
.datepickerdemoBasicUsage {
/** Demo styles for mdCalendar. */ }
.datepickerdemoBasicUsage md-content {
padding-bottom: 200px; }
.datepickerdemoBasicUsage .validation-messages {
font-size: 12px;
color: #dd2c00;
margin: 10px 0 0 25px; }
</style>
<script src="lib/angular.js"></script>
<script>
angular.module("datepickerBasicUsage",
["ngMaterial", "ngMessages"]).controller("AppCtrl", function($scope) {
$scope.myDate = new Date();
$scope.minDate = new Date(
$scope.myDate.getFullYear(),
$scope.myDate.getMonth() - 2,
$scope.myDate.getDate());
$scope.maxDate = new Date(
$scope.myDate.getFullYear(),
$scope.myDate.getMonth() + 2,
$scope.myDate.getDate());
$scope.onlyWeekendsPredicate = function(date) {
var day = date.getDay();
return day === 0 || day === 6;
}
});
</script>
</head>
<body>
<h4>Only weekends within given range are selectable</h4>
< ng-model="myDate" md-placeholder="Enter date"
md-min-date="minDate" md-max-date="maxDate"
md-date-filter="onlyWeekendsPredicate"></>
<h4>With ngMessages</h4>
<form name="myForm">
<md-datepicker name="dateField" ng-model="myDate" md-placeholder="Enter date"
required md-min-date="minDate" md-max-date="maxDate"
md-date-filter="onlyWeekendsPredicate"></md-datepicker>
<div class="validation-messages" ng-messages="myForm.dateField.$error">
<div ng-message="valid">The entered value is not a date!</div>
<div ng-message="required">This date is required!</div>
<div ng-message="mindate">Date is too early!</div>
<div ng-message="maxdate">Date is too late!</div>
<div ng-message="filtered">Only weekends are allowed!</div>
</div>
</form>
</md-content>
</div>
</body>
</html>
Someone could see where it was wrong?
This appears on screen
Only weekends within given range are selectable
< ng-model="myDate" md-placeholder="Enter date" md-min-date="minDate" md-max-date="maxDate" md-date-filter="onlyWeekendsPredicate">
With ngMessages
The entered value is not a date!
This date is required!
Date is too early!
Date is too late!
Only weekends are allowed!
UPDATING///////////////////////////////////////////////////////////
div ng-controller="AppCtrl" style='padding: 40px;' ng-cloak>
<md-content>
<h4>Standard date-picker</h4>
<md-datepicker ng-model="myDate" md-placeholder="Enter date"></md-datepicker>
<h4>Disabled date-picker</h4>
<md-datepicker ng-model="myDate" md-placeholder="Enter date" disabled></md-datepicker>
<h4>Date-picker with min date and max date</h4>
<md-datepicker ng-model="myDate" md-placeholder="Enter date"
md-min-date="minDate" md-max-date="maxDate"></md-datepicker>
<h4>Only weekends are selectable</h4>
<md-datepicker ng-model="myDate" md-placeholder="Enter date"
md-date-filter="onlyWeekendsPredicate"></md-datepicker>
<h4>Only weekends within given range are selectable</h4>
<md-datepicker ng-model="myDate" md-placeholder="Enter date"
md-min-date="minDate" md-max-date="maxDate"
md-date-filter="onlyWeekendsPredicate"></md-datepicker>
<h4>With ngMessages</h4>
<form name="myForm">
<md-datepicker name="dateField" ng-model="myDate" md-placeholder="Enter date"
required md-min-date="minDate" md-max-date="maxDate"
md-date-filter="onlyWeekendsPredicate"></md-datepicker>
<div class="validation-messages" ng-messages="myForm.dateField.$error">
<div ng-message="valid">The entered value is not a date!</div>
<div ng-message="required">This date is required!</div>
<div ng-message="mindate">Date is too early!</div>
<div ng-message="maxdate">Date is too late!</div>
<div ng-message="filtered">Only weekends are allowed!</div>
</div>
</form>
</md-content>
</div>
This is probably happening because you are not assigning any controller to your HTML using the ng-controller tag, you are just instantiating it ...
– pmargreff
how would I do that?
– wladyband
detailed answer below.
– pmargreff