gpt4 book ai didi

angularjs - Angular 带错误 : [$injector:unpr] Unknown provider: $datepickerProvider

转载 作者:行者123 更新时间:2023-12-04 21:42:51 24 4
gpt4 key购买 nike

我正在学习 AngularJs,并且有很多新术语,或者我开始理解这些术语,但是我似乎无法弄清楚我做错了什么。

我要做的就是使用 Angular-Strap 在我的页面上加载日期选择器。
http://mgcrea.github.io/angular-strap/##datepickers

我得到的错误到目前为止还没有弄清楚为什么是:

Uncaught Error: [$injector:modulerr] Failed to instantiate module mgcrea.ngStrap due to: Error: [$injector:unpr] Unknown provider: $datepickerProvider



我的基本理解告诉我 Angular 正在尝试注入(inject)它所依赖的模块,但我在文档中找不到 $datepickerProvider 是什么,我使用的是网站上的示例代码。

Html - 标记
<!DOCTYPE html>
<html lang="en" ng-app="mgcrea.ngStrap">
<head>
...
</head>
<body ng-controller="ZenwireController">
<div class="bs-example" style="padding-bottom: 24px;" append-source>
<form name="datepickerForm" class="form-inline" role="form">
<!-- Basic example -->
<div class="form-group" ng-class="{'has-error': datepickerForm.date.$invalid}">
<label class="control-label"><i class="fa fa-calendar"></i> Date <small>(as date)</small></label>
<input type="text" class="form-control" ng-model="selectedDate" name="date" bs-datepicker>
</div>
<!-- Custom example -->
<div class="form-group" ng-class="{'has-error': datepickerForm.date2.$invalid}">
<label class="control-label"><i class="fa fa-calendar"></i> Date <small>(as number)</small></label>
<input type="text" class="form-control" ng-model="selectedDateAsNumber" data-date-format="yyyy-MM-dd" data-date-type="number" data-min-date="02/10/86" data-max-date="today" data-autoclose="1" name="date2" bs-datepicker>
</div>
<hr>
<!-- Date range example -->
<div class="form-group">
<label class="control-label"><i class="fa fa-calendar"></i> <i class="fa fa-arrows-h"></i> <i class="fa fa-calendar"></i> Date range <small>(dynamic)</small></label><br>
<div class="form-group" class="col-xs-3">
<input type="text" class="form-control" ng-model="fromDate" data-max-date="{{untilDate}}" placeholder="From" bs-datepicker>
</div>
<div class="form-group" class="col-xs-3">
<input type="text" class="form-control" ng-model="untilDate" data-min-date="{{fromDate}}" placeholder="Until" bs-datepicker>
</div>
</div>
</form>
</div>
</div>
</body>
</html>

AngularJs - 代码
var app = angular.module('mgcrea.ngStrap', ['ngAnimate', 'ngSanitize', 'mgcrea.ngStrap']);

app.controller('ZenwireController', function ($scope) {
});

'use strict';

angular.module('mgcrea.ngStrap')

.config(function ($datepickerProvider) {
angular.extend($datepickerProvider.defaults, {
dateFormat: 'dd/MM/yyyy',
startWeek: 1,
autoClose: true,
minDate: "today"
});
})

.controller('DatepickerController', function ($scope, $http) {

$scope.selectedDate = new Date();
$scope.selectedDateAsNumber = Date.UTC(1986, 1, 22);
// $scope.fromDate = new Date();
// $scope.untilDate = new Date();
$scope.getType = function (key) {
return Object.prototype.toString.call($scope[key]);
};

});

我正在加载的脚本是,
    bundles.Add(new ScriptBundle("~/bundles/angularjs").Include(
"~/Scripts/angular.js",
"~/Scripts/angular-animate.js",
"~/Scripts/angular-sanitize.js",
"~/Scripts/angular-strap.min.js",
"~/Scripts/angular-strap.tpl.min.js",
"~/Scripts/angular-strap/date-parser.min.js",
"~/Scripts/angular-strap/tooltip.min.js"));

最佳答案

您正在声明模块“mgcrea.ngStrap”

更改 HTML 和 AngularJS 代码

HTML 标记

<!DOCTYPE html>
<html lang="en" ng-app="myapp">
<head>
...
</head>

Angular 码
var app = angular.module('myapp', ['ngAnimate', 'ngSanitize', 'mgcrea.ngStrap']);
app.controller('ZenwireController', function ($scope) {
});

关于angularjs - Angular 带错误 : [$injector:unpr] Unknown provider: $datepickerProvider,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22241572/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com