Question

I am learning AngularJs and there are a lot of new terms or which I am beginning to understand however this one I can't seem to figure out what I am doing wrong.

All I am trying to do is use Angular-Strap to load a datepicker on my page. http://mgcrea.github.io/angular-strap/##datepickers

The error I am getting and so far haven't figured out why is:

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

My basic understanding tells me Angular is trying to inject a module it is dependent on but I can't find anywhere in documentation what the $datepickerProvider is, I am using the example code from the website.

Html - Markup

<!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 - Code

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]);
    };

});

The scripts I am loading are,

    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"));
Was it helpful?

Solution

Your are declaring the Module 'mgcrea.ngStrap'

Make Changes in HTML and AngularJS Code

HTML Mark up

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

Angular Code

var app = angular.module('myapp', ['ngAnimate', 'ngSanitize', 'mgcrea.ngStrap']);
    app.controller('ZenwireController', function ($scope) {
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top