3

I need to compile a directive because it needs an ID that comes back from the DB, but can't seem to get that to persist through to the directive.

$scope.orderInfo = {
  orderId: 'lkdfj232jh'
};
$scope.compile = function() {
   var html = $compile('<apps orderId="orderInfo.orderId"></apps>')($scope);
   $('#apps').append(html);
};

return {
  templateUrl: 'apps.html',
  restrict: 'E',
  scope: {
    orderId: '='
  },
  controller: function($scope) {
    console.log($scope.orderId);
  }
}

orderId is always undefined inside directive.

Plunker

swade
  • 668
  • 2
  • 7
  • 15

1 Answers1

2

Attribute name should be order-id(hyphenated) not orderId

$scope.compile = function() {
   var html = $compile('<apps order-id="orderInfo.orderId"></apps>')($scope);
   $('#apps').append(html);
};

Working Plnkr

Vinay K
  • 5,562
  • 1
  • 18
  • 27