0

So I'm getting an error in my template with it not liking the ng-model="event.{{name}}". I was wondering how I can get the model to be ng-model="event.date_end".

I am also wondering if this jquery datetimepicker will initialize correctly in the link (It worked when I just had it as a function in the .html file, but not when I put it in the controller.)

Also I was having to use jquery to get trigger an 'input' on the input to update the model, but I was hoping to do it the angular way within the directive.

Hopefully I'm not too far off the angular way with this.

Thanks.

HTML

<date-picker id="dateendPicker" name="{{date_end}}"></date-picker>

JS

App.directive('datePicker', function(){
return {
scope: {
    name : '@'
},
restrict: 'AE',
replace: 'true',
template: '<div class="date"><div class="input-group"><input type="text" class="form-control" id="{{name}}" name="{{name}}" ng-model="event.{{name}}" ng-blur="setModel()" required/><span class="input-group-addon"><i class="fa fa-calendar"></i></span></div></div>',
link: function(scope, elem, attrs){

    attrs.$observe('key', function(value) {
       var this_id = value;
    });

    $(''+this_id+'').datetimepicker({
        pickTime: false,
            icons: {
            time: "fa fa-clock-o",
            date: "fa fa-calendar",
            up: "fa fa-arrow-up",
            down: "fa fa-arrow-down"
        }
    });

    //set model on blur
    function setModel(){
        elem.find('input').trigger('input');
    }

    }
  }
});
jaruesink
  • 1,205
  • 2
  • 14
  • 24
  • is that doing what you think it's doing? `{{date_end}}` suggests you're sending in the value assigned to variable `date_end` on your scope, not the literal string `date_end`, so it can never be that in your directive – Jorg Jun 30 '14 at 06:47
  • 1
    Why not use a Angular-Strap or angular-bootstrap as they have already solved this problem? – Jon Jun 30 '14 at 06:48
  • I'm using this one http://eonasdan.github.io/bootstrap-datetimepicker/ and think it's design is better than the other pickers. – jaruesink Jun 30 '14 at 07:30

0 Answers0