http://jsfiddle.net/edwardtanguay/3tef6dmr/5
我已使用thelabel
将变量=
传递到我的指令中,我希望能够在我的模板中使用{{thelabel}}
并使用$scope.thelabel
在我的控制器中,但变量未定义。
如何访问变量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'
};
});