I am trying to create a directive that would create input(s) field with different types and different numbers. That works fine, but my problem is, I can't use any of my ng-model inside my directive's input field. My code is given below:
HTML ::
<form method="post" ng-submit="CheckAddReceivedGoods($event, limit)" novalidate>
<ul class="checkboxUl" ng-repeat="cat in InvoicesProduct">
<invoice-product info="cat" num="$index"></invoice-product>
</ul>
</form>
AngularJS Code ::
var apps = angular.module("ReceivedGoodsApps", ['ngRoute']);
apps.directive("invoiceProduct", function () {
return {
restrict: "E",
scope: {
productList: "=info",
pos: "=num"
},
template: '<div>',
link: function (scope, element, attrs) {
var template = '';
position = scope.pos + 1;
HasUniqueSpecifier = scope.productList.HasUniqueSpecifier;
if (HasUniqueSpecifier === "NoUniqueIdentifier") {
template += '<input type="text" ng-model="Quantity' + position + '" />';
} else if (HasUniqueSpecifier === "UniqueIdentifier") {
template += '<textarea rows="7" cols="35" ng-model="UniqueIdentifier' + position + '" ></textarea>';
} else if (HasUniqueSpecifier === "SerialUniqueIdentifier") {
template += '<input type="text" ng-model="end' + position + '" /> ';
}
element.find('div').append(template);
}
};
});
apps.controller("ReceivedGoodsCtrl", function ($scope, $http) {
$scope.CheckAddReceivedGoods = function ($event, limit) {
for (var i = 1; i <= limit; i++) {
// $scope['Quantity' + i] is undefined
// $scope['UniqueIdentifier' + i] is undefined
// $scope['start' + i] is undefined
}
};