Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular UI Bootstrap monthpicker

I am trying to setup the date picker to work as a month picker. Everything works as expected as long as you're clicking a month and/or going to prev/next year. However, if you want to broaden the year selection by clicking the current year from the top, I get a JavaScript error.

HTML:

<div ng-app="app">
    <div ng-controller="TestController">
        <input type="date" class="form-control" ng-model="date" datepicker-popup="MM/yyyy" is_open="date_opened" ng-focus="date_opened = true" ng-click="date_opened = true" datepicker-options="datepickerOptions">
    </div>
</div>

JS:

(function() {
    'use strict';

    var app  = angular.module('app', [
        'ui.bootstrap'
    ]);

    app.controller('TestController', ['$scope', function($scope) {
        $scope.datepickerOptions = {
            datepickerMode: "'month'",
            minMode: 'month'
        };
    }]);
})();

Here's the JSFiddle demonstrating it (angularjs 1.2.26, ui-bootstrap 0.11.2).

like image 904
valmarv Avatar asked Oct 20 '14 12:10

valmarv


People also ask

Can I use bootstrap with Angular?

Adding bootstrap using the angular. Open the file and perform the following commands, node_modules/bootstrap/dist/css/bootstrap. css in the projects->architect->build->styles array, node_modules/bootstrap/dist/js/bootstrap. js in the projects->architect->build->scripts array, node_modules/bootstrap/dist/js/bootstrap.

What is $Uibmodal in AngularJS?

$uibmodal is a service to create modal windows. Uibmodal is the UI Bootstrap component written in AngularJS. It enables us to use Bootstrap in AngularJS. It provides directives for all bootstrap with some extra like, datepicker, timepicker etc.

What is UIB accordion?

uib-accordion-group settings heading (Default: none ) - The clickable text on the group's header. You need one to be able to click on the header for toggling. is-disabled $ (Default: false ) - Whether the accordion group is disabled or not.

Which is the directive bootstraps AngularJS framework?

The ng-app directive is a starting point of AngularJS Application. It initializes the AngularJS framework automatically. AngularJS framework will first check for ng-app directive in a HTML document after the entire document is loaded and if ng-app is found, it bootstraps itself and compiles the HTML template.


1 Answers

Make the following changes as highlighted in comments:

 (function() {
'use strict';

var app  = angular.module('app', [
    'ui.bootstrap'
]);

app.controller('TestController', ['$scope', function($scope) {
    $scope.datepickerOptions = {
        datepickerMode: "month",     // Remove Single quotes
        minMode: 'month'
    };
}]);

})();

like image 56
Rohit Aggarwal Avatar answered Nov 15 '22 05:11

Rohit Aggarwal