I am trying to add date picker to my HTML page where I am doing data binding using angular js. I have also a requirement to export the data to CSV file which I am doing using ng-csv directive.
I have tried the question present in stack over flow
AngularJS - jQuery UI - binding issue
Here is my fiddle for the same
https://jsfiddle.net/DivB/4uae2gor/3/
html
<div ng-app="myApp">
<div ng-app="myApp">
<div ng-controller="MainCtrl">
<p><b>Date from</b> <input id="date1" value="1/1/1980" ng-model="fromDate" my-datepicker /></p>
<p><b>Data do:</b> <input id="date2" value="1/1/1980" ng-model="toDate" my-datepicker /></p>
Choosen date from: {{fromDate}} to: {{toDate}}
<br />
<button type="button" class="btn btn-primary" ng-csv="getArray" csv-header="getHeader()" filename="CO_Status.csv" field-separator=","><span>Export to CSV</span></button> </br>
</div>
and script
var myApp = angular.module('myApp', ['myApp.directives','ngSanitize','ngCsv']);
function MainCtrl($scope) {
$scope.getHeader = function () {return ["CO Number", "Client Name" ]};
$scope.getArray = [ {A:"a",B:"b"},{A:"c",B:"d"} ];
}
angular.module('myApp.directives', [])
.directive('myDatepicker', function() {
return function(scope, element, attrs) {
element.datepicker({
changeYear : true,
changeMonth : true,
appendText : '(yyyy-mm-dd)',
dateFormat : 'yy-mm-dd',
onSelect: function(dateText, inst) {
var mdlAttr = $(this).attr('ng-model');
scope[attrs.ngModel] = dateText;
scope.$apply();
}
});
}
});
If I remove all the stuff related to ng-csv(External resources ng-csv and sanitize, include 'ngcsv' and 'ngSanitize' in app module) for the code works. But together it doesn't works.
Can anyone please help me ? Thanks in advance.