带条形码生成器的动态网格 ANGULAR
Dynamic Grid ANGULAR with BARCODE generator
我正在学习Angular。
我正在制作一个应用程序:用户从一个 html select 离子中进行选择,然后填写两个输入字段。在此之后,用户按下更新,条形码脚本生成带有 3 个参数的代码图像:第一个 select 和第二个输入。 (这三个用一些空格隔开)。到目前为止,没问题。
我添加了用于添加新表单的按钮,json 数组正确保存了输入。我想为每个编译后的表格生成一个条形码。我能怎么做?
这是我正在做的一个简单例子:
http://plnkr.co/edit/hxZb6g9tkwN0zpRmOMjw?p=preview
在html的末尾可以找到条形码的脚本:
<div class="ean">
<img id="barcodeImage" style="border: solid 1px black;"/>
<script type="text/javascript">
function updateBarcode()
{
var barcode = new bytescoutbarcode128();
var space= " ";
var value = document.getElementById("barcodeValue").value;
var value1 = document.getElementById("barcodeValue1").value;
var value2 = document.getElementById("barcodeValue2").value;
barcode.valueSet(value + space + value1 + space + value2);
barcode.setMargins(5, 5, 5, 5);
barcode.setBarWidth(2);
var width = barcode.getMinWidth();
barcode.setSize(width, 100);
var barcodeImage = document.getElementById('barcodeImage');
barcodeImage.src = barcode.exportToBase64(width, 100, 0);
}
</script>
您应该创建 directive (also take a look here - http://www.ng-newsletter.com/posts/directives.html, http://www.sitepoint.com/practical-guide-angularjs) 来生成条形码,并将此指令放入模板中的 ng-repeat 循环中:
app.directive('barcode', function(){
return{
restrict: 'AE',
template: '<img id="barcodeImage" style="border: solid 1px black;" src="{{src}}"/>',
scope: {
food: '='
},
link: function($scope){
$scope.$watch('food', function(food){
console.log($scope.food);
var barcode = new bytescoutbarcode128();
var space= " ";
barcode.valueSet([$scope.food.selectproduct, $scope.food.Quantity1, $scope.food.Quantity2].join(space));
barcode.setMargins(5, 5, 5, 5);
barcode.setBarWidth(2);
var width = barcode.getMinWidth();
barcode.setSize(width, 100);
$scope.src = barcode.exportToBase64(width, 100, 0);
}, true);
}
}
});
我正在学习Angular。 我正在制作一个应用程序:用户从一个 html select 离子中进行选择,然后填写两个输入字段。在此之后,用户按下更新,条形码脚本生成带有 3 个参数的代码图像:第一个 select 和第二个输入。 (这三个用一些空格隔开)。到目前为止,没问题。
我添加了用于添加新表单的按钮,json 数组正确保存了输入。我想为每个编译后的表格生成一个条形码。我能怎么做? 这是我正在做的一个简单例子:
http://plnkr.co/edit/hxZb6g9tkwN0zpRmOMjw?p=preview
在html的末尾可以找到条形码的脚本:
<div class="ean">
<img id="barcodeImage" style="border: solid 1px black;"/>
<script type="text/javascript">
function updateBarcode()
{
var barcode = new bytescoutbarcode128();
var space= " ";
var value = document.getElementById("barcodeValue").value;
var value1 = document.getElementById("barcodeValue1").value;
var value2 = document.getElementById("barcodeValue2").value;
barcode.valueSet(value + space + value1 + space + value2);
barcode.setMargins(5, 5, 5, 5);
barcode.setBarWidth(2);
var width = barcode.getMinWidth();
barcode.setSize(width, 100);
var barcodeImage = document.getElementById('barcodeImage');
barcodeImage.src = barcode.exportToBase64(width, 100, 0);
}
</script>
您应该创建 directive (also take a look here - http://www.ng-newsletter.com/posts/directives.html, http://www.sitepoint.com/practical-guide-angularjs) 来生成条形码,并将此指令放入模板中的 ng-repeat 循环中:
app.directive('barcode', function(){
return{
restrict: 'AE',
template: '<img id="barcodeImage" style="border: solid 1px black;" src="{{src}}"/>',
scope: {
food: '='
},
link: function($scope){
$scope.$watch('food', function(food){
console.log($scope.food);
var barcode = new bytescoutbarcode128();
var space= " ";
barcode.valueSet([$scope.food.selectproduct, $scope.food.Quantity1, $scope.food.Quantity2].join(space));
barcode.setMargins(5, 5, 5, 5);
barcode.setBarWidth(2);
var width = barcode.getMinWidth();
barcode.setSize(width, 100);
$scope.src = barcode.exportToBase64(width, 100, 0);
}, true);
}
}
});