I wrote a directive that displays one button for each product passed to the directive. The product should also be passed to the function subscribe of the directive when the button is clicked.
The issue I have is that the parameter is not passed to the function.
The directive
directives.directive('subscriptionItem', function () {
return {
scope: {
// Two way binding, = is equivalent to '=activeSubscription'
activeSubscription: '=',
products: '=',
googleLogin: '&',
subscribe: '&'
},
restrict: 'E',
replace: 'true',
templateUrl: 'common/directives/subscription-item.tpl.html'
};
});
The template
<div>
<ion-item class="item-text-wrap">
<h2>{{activeSubscription.status}} - {{activeSubscription.action}}</h2>
<p>{{activeSubscription.description}}</p>
</ion-item>
<ion-item ng-repeat="product in products" class="item-text-wrap" ng-if="activeSubscription.action === 'PAID'">
<h2>{{product.title | limitTo: product.title.length - 21}}</h2>
<p>{{product.description}}</p>
<button class="button button-block button-positive" ng-click="subscribe(product.productId)">
Buy for {{product.price}} - {{product.productId}}
</button>
</ion-item>
</div>
The product.productId is correctly displayed but not passed to the function.
The directive usage
<subscription-item active-subscription="activeSubscription" products="products" google-login="googleLogin()" subscribe="subscribe(sku)"></subscription-item>
The subscribe function in the parent controller scope
$scope.subscribe = function (sku) {
console.log('subscribe ' + sku)
InAppBillingService.subscribe(sku)
.then(function () {
console.log('Success');
})
.catch(function (error) {
$cordovaToast.showLongBottom(error);
});
}