2

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

});
Brett
  • 4,268
  • 1
  • 13
  • 28
Edward Tanguay
  • 189,012
  • 314
  • 712
  • 1,047
  • 1
    this should help: http://stackoverflow.com/questions/14050195/what-is-the-difference-between-and-in-directive-scope#answer-14063373 – lukkea Sep 11 '15 at 15:28
  • 2
    You need `@` not `=`. `=` is for 2 way binding when providing a property with value, if you are binding text then it should just be `@`. – PSL Sep 11 '15 at 15:39
  • sorry psl , but his problem is not @ or = , he is wrapping an external js , he need to notify angular about the changes , reopen so i can post the solution – shaouari Sep 11 '15 at 15:41
  • try this : http://jsfiddle.net/3tef6dmr/6/ , change the date it will update thelabel – shaouari Sep 11 '15 at 15:47

0 Answers0