如何使用我传入我的指令的这个属性?

时间:2015-09-11 15:20:00

标签: angularjs angularjs-directive

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'
    };

});

0 个答案:

没有答案