【发布时间】:2015-08-26 19:25:19
【问题描述】:
总是出错:找不到指令“datepicker”所需的控制器“ngModel”!
如果我在另一个应用程序中移动相同的代码,它会完美运行,所以我错过了什么
<p class="input-group">
<input type="text"
datepicker-popup="{{format}}"
ng-model="fromdate"
is-open="open"
ng-required="true"
class="form-control" />
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="open = !open;">
<i class="glyphicon glyphicon-calendar"></i>
</button>
</span>
</p>
要测试的完整控制器:
app.controller('dateCtrl', ['$scope', function ($scope) {
$scope.open = false;
$scope.fromdate = '';
}])
这是完整的错误:
错误:[$compile:ctreq] 控制器 'ngModel',指令 'datepicker' 需要,找不到!
http://errors.angularjs.org/1.4.2/$compile/ctreq?p0=ngModel&p1=datepicker
at REGEX_STRING_REGEXP (http://localhost/someapp/Scripts/angular.js:68:12)
at getControllers (http://localhost/someapp/Scripts/angular.js:8009:19)
at nodeLinkFn (http://localhost/someapp/Scripts/angular.js:8156:33)
at delayedNodeLinkFn (http://localhost/someapp/Scripts/angular.js:8400:11)
at compositeLinkFn (http://localhost/someapp/Scripts/angular.js:7543:13)
at publicLinkFn (http://localhost/someapp/Scripts/angular.js:7418:30)
at $get.boundTranscludeFn (http://localhost/someapp/Scripts/angular.js:7562:16)
at controllersBoundTransclude (http://localhost/Tsomeapp/Scripts/angular.js:8179:18)
at ngDirective.link (http://localhost/someapp/Scripts/angular.js:27880:5)
at invokeLinkFn (http://localhost/someapp/Scripts/angular.js:8652:9) <li ng-transclude="">(anonymous function) @ angular.js:12332$get @ angular.js:9111invokeLinkFn @ angular.js:8654nodeLinkFn @ angular.js:8152compositeLinkFn @ angular.js:7543nodeLinkFn @ angular.js:8147compositeLinkFn @ angular.js:7543publicLinkFn @ angular.js:7418$get.boundTranscludeFn @ angular.js:7562controllersBoundTransclude @ angular.js:8179ngIfWatchAction @ angular.js:23814$get.Scope.$digest @ angular.js:15685$get.Scope.$apply @ angular.js:15953(anonymous function) @ angular.js:23305n.event.dispatch @ jquery-2.1.4.min.js:3n.event.add.r.handle @ jquery-2.1.4.min.js:3
angular.js:12332
TypeError: Cannot read property '0' of undefined
at k (ui-bootstrap-tpls.min.js:8)
at Scope.$get.Scope.$broadcast (angular.js:16167)
at ui-bootstrap-tpls.min.js:8
at angular.js:17711
at completeOutstandingRequest (angular.js:5396)
at angular.js:5668
它只渲染
【问题讨论】:
-
{{format}}解析为什么?那将是正在使用的模板 -
$scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate']; $scope.format = $scope.formats[0];那是日期格式
-
$scope.fromdate应该是Date,而不是String;试试$scope.fromdate = new Date(); -
我也试过了,即使是 type ='date' 但注意到工作,相同的代码在其他应用程序中工作,我尝试通过复制和粘贴,真的很奇怪。
标签: angularjs twitter-bootstrap-3 datepicker