【发布时间】:2015-04-15 16:33:39
【问题描述】:
我正在尝试调整 angular-pickdate (https://github.com/jimibi/angular-pickadate) 模块以满足我的需求,但由于无法按照我习惯的方式发出 GET 请求,因此我陷入了停顿。
我的代码是: ...
.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");});
...
这段代码给我的错误是:
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)
此错误与 $http 请求有关。
有没有人知道我为什么会收到这个错误,我该如何解决? 提前致谢
【问题讨论】:
-
试试
$http.get('myplace/script_lotacoes.php').then(function() { alert('hheheh'); }); -
我做到了。它给了我以下错误:ypeError: Cannot read property 'get' of undefined at Scope.angular.module.provider.factory.directive.link.scope.render (angular-pickadate.js:123)...
-
还可以尝试将
$http注入您的指令定义,而不是link函数 -
也这样做了,哈哈同样的错误......这很奇怪。
-
您是否从
link()中删除了http注入?
标签: javascript angularjs httprequest ionic-framework ionic