I'm trying to adapt the angular-pickdate (https://github.com/jimibi/angular-pickadate) module to fit my needs, and I've reached a standstill, due to the impossibility of making a GET request the way I'm used to.
My code is : ...
.directive('pickadate', ['$locale', 'pickadateUtils', 'pickadateI18n', 'dateFilter', function($locale, dateUtils, i18n, dateFilter) {
return {
require: 'ngModel',
scope: {
date: '=ngModel',
defaultDate: '=',
minDate: '=',
maxDate: '=',
disabledDates: '='
},
template:
...,
link: function(scope, element, attrs, ngModel,$http) {
var minDate = scope.minDate && dateUtils.stringToDate(scope.minDate),
maxDate = scope.maxDate && dateUtils.stringToDate(scope.maxDate),
disabledDates = scope.disabledDates || [],
currentDate = (scope.defaultDate && dateUtils.stringToDate(scope.defaultDate)) || new Date();
scope.dayNames = $locale.DATETIME_FORMATS['SHORTDAY'];
scope.currentDate = currentDate;
scope.t = i18n.t;
scope.render = function(initialDate,$http) {
initialDate = new Date(initialDate.getFullYear(), initialDate.getMonth(), 1, 3);
$http({url: 'myplace/script_lotacoes.php', method: 'GET'}).success(function(){alert("hheheh");}).error(function(){alert("oops");});
...
the error that this code gives me is :
TypeError: undefined is not a function
at Scope.angular.module.provider.factory.directive.link.scope.render (angular-pickadate.js:122)
at angular.module.provider.factory.directive.link.ngModel.$render (angular-pickadate.js:191)
at Object.ngModelWatch (ionic.bundle.js:31576)
at Scope.$get.Scope.$digest (ionic.bundle.js:22518)
at Scope.$get.Scope.$apply (ionic.bundle.js:22789)
at done (ionic.bundle.js:17942)
at completeRequest (ionic.bundle.js:18132)
at XMLHttpRequest.requestLoaded (ionic.bundle.js:18073)
This error is related to the $http request.
Does anyone have a clue why I get this error, and how can I fix it? Thanks in advance
Inject the $http
service in the directive:
.directive('pickadate', ['$http', '$locale', 'pickadateUtils', 'pickadateI18n', 'dateFilter', function($http, $locale, dateUtils, i18n, dateFilter) {
You are injecting $http
into your link
function and well as your scope.render
function. Remove these two injection attempts- you'll only need to inject this into your directive.
.directive('pickadate', ['$locale', 'pickadateUtils', 'pickadateI18n', 'dateFilter', '$http', function($locale, dateUtils, i18n, dateFilter, $http) {