Ich kenne angularjs, aber das ist das erste Mal, dass ich eckige Anweisung schreibe, also versuche ich Anweisung für progressbar jedes Mal zu erstellen, wenn ich eine Nachricht im Controller erhalte, basierend auf der Berechnung der Stringgröße und Umwandlung in Bytes für progressbar.Problem mit unter Code i siehe Fehler $scope.random
ist keine Funktion. Irgendeine Idee, was falsch umgesetzt wird?
directive.js
angular.module("App").directive('progressBarCustom', function() {
return {
restrict: 'E',
scope: {
message: "="
},
templateUrl: '/view/partials/progressbar.html',
controller: function($scope) {
var data = $scope.message;
var currentFileBytes = [];
var currentBytesSum;
$scope.maxBytes = 3000;
getByteLen(data);
$scope.random = function(value) {
$scope.dynamic = value;
$scope.downloadPercentage = parseFloat((value/$scope.maxBytes) * 100).toFixed(0);
console.log('current value-dynamic', $scope.dynamic);
};
function getByteLen(normal_val) {
// Force string type
normal_val = String(normal_val);
currentFileBytes.push(byteLen);
currentBytesSum = currentFileBytes.reduce(function(a, b) {
return a + b;
}, 0);
$scope.random(currentBytesSum);
formatBytes(currentBytesSum);
return byteLen;
}
function formatBytes(bytes, decimals) {
var data = parseFloat((bytes/Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
console.log('sum of all the bytes', data);
$scope.currentBytes = data;
}
}
}
});
progressbar.html
<uib-progressbar type="success" class="progress-striped" max="max" animate="true" value="dynamic"><span>{{downloadPercentage}}%</span></uib-progressbar>
main.html
<progress-bar-custom message="event"></progress-bar-custom>
controller.js
$scope.event = ["lorem ipsum","lorem ipsum"];
Perfect! Danke für die Hilfe. – hussain