4

I am trying to pass json object to angular directive but can't find any solution yet.

here is the code.

Directive

 function agEcalendar() {
    var directive = {
      restrict: 'E',
      templateUrl: 'app/components/ecalendar/ecalendar.html',
      scope: {
          event: '@event'
      },
      controller: EcalendarController,
      controllerAs: 'vm',
      bindToController: true
    };

    return directive;
  }

and here i am calling the directive in jade

ag-ecalendar(event='{{vm.calendar.event}}')
Ahmad Abbasi
  • 1,776
  • 6
  • 29
  • 43
  • What are you trying to accomplish with this directive? Should the `controller` be in quotes? `controller: "EcalendarController"` – Hanlet Escaño May 18 '16 at 14:35

1 Answers1

4

Do pass object using <(new one way binding options) which will give you ability to pass object to directive isolated scope.

scope: {
    event: '<event'
},

HTML

ag-ecalendar(event='vm.calendar.event')

In current case it is getting passed with @ is nothing but converting object value to string.

Note The suggested way would work for Angular 1.5+ version, otherwise you need to make it as event: '=event'(eventually that will enable two way binding)

Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299