http://jsfiddle.net/edwardtanguay/3tef6dmr/5
I'm passing the variable thelabel
into my directive with a =
and I expect to be able to use it with {{thelabel}}
in my template and with $scope.thelabel
in my controller, but the variable is undefined.
How do I access the variable thelabel
?
HTML
<script type="text/ng-template" id="templateCalendarPicker">
<div>[{{thelabel}}]</div>
<div class='input-group date datepicker_format' id='datepicker'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</script>
<div ng-controller="mainController">
<div calendar-picker thelabel="testtitle"></div>
</div>
JavaScript
angular.module('myApp', [])
.controller('mainController', function($scope) {
//...
})
.directive('calendarPicker', function() {
var controller = function ($scope) {
var vm = this;
console.log($scope.
$scope.showInfo = function() {
return 'nnn';
};
$('#datepicker').datetimepicker({
format:'YYYY-MM-DD',
defaultDate: new Date('2015-09-01'),
disabledDates: [
moment("2015-12-25")
]
});
};
return {
restrict: 'A',
scope: {
thelabel : '='
},
controller: controller,
controllerAs: 'vm',
bindToController: true,
templateUrl: 'templateCalendarPicker'
};
});