I have a custom directive in AngularJS and I want to pass a variable to it from my controller.
Controller:
angular.
module('orderOverview').
component('orderOverview', {
templateUrl: 'home-page/order-overview/order-overview.template.html',
controller: ['Orders',
function ControllerFunction(Orders) {
var self = this;
// Order Info
Orders.getOverview().$promise.then(function(data) {
self.LineItems = data;
});
// Order Info
}
]
});
Directive
angular.
module('myApp').
directive('gvInitializeOrderStatus', function() {
return {
scope: {
field: '@',
myData: '='
},
link: function(scope, element) {
console.log('field:', scope.field);
console.log('data:', scope.myData);
}
}
});
HTML
<div gv-initialize-order-status field="InquiryDone" myData="$ctrl.LineItems">
<span class="tooltiptext">Inquiry</span>
</div>
When I load the page, field
logs fine, however data
is undefined.
I've tried this a lot of ways, but this is how it should work in my mind if it gives you any idea of what I'm thinking of.
At another point in the same template I pass ng-repeat
data to a directive just fine, but in this case I specifically don't want to ng-repeat
ng-repeat HTML that successfully passed data
<li ng-repeat="lineItem in $ctrl.LineItems">
<div class="status-circle"
ng-click="toggleCircle($event, lineItem, 'InquiryDone')"
field="InquiryDone" item="lineItem" gv-initialize-statuses>
<span class="tooltiptext">Inquiry</span>
</div>
</li>
In my other directive, gv-initialize-statuses
, I use the same concept in my scope
object and have something like scope: { 'field': '=' }
and it works just fine.
How can I accomplish this without using ng-repeat?