2016-08-25 3 views
0

私はangularjsを知っていますが、これは最初の私は角度指示を書いているので、私はプログレスバーの指示を作成しようとしています毎回私はそれに基づいてコントローラのメッセージを受け取る文字列のサイズを計算し、progressbar.Problemエラー$scope.randomは機能ではありませんを参照してください。何が間違って実装されているか?

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"]; 

答えて

1

$scope.randomが割り当てられる前にgetByteLenに電話しています。

使用この代わりに:

 $scope.random = function(value) { 
      $scope.dynamic = value; 
      $scope.downloadPercentage = parseFloat((value/$scope.maxBytes) * 100).toFixed(0); 
      console.log('current value-dynamic', $scope.dynamic); 
     }; 
     getByteLen(data); 
+0

パーフェクト!助けてくれてありがとう。 – hussain

関連する問題