0

This is my script in which I included in my html code-

<div class="progress-bar"></div>
<script type="text/javascript">

  $('.progress-bar').gradientProgressBar({
      value: $(this).attr('$scope.moodvalue'),
      size: 400,
      fill: {
          gradient: ["red", "green", "yellow"]
      }
  });
</script>
</div>

and I am Passing $scope.moodevalue from angular code. But as I am getting $scope.moodvalue = 0.21, but the change is not appearing on my progress bar.

please help me, how to pass dynamic value to script.

Thanks in Advance.

4
  • 2
    This might help: stackoverflow.com/questions/31604547/… Commented Feb 22, 2017 at 8:26
  • Would you share html. Commented Feb 22, 2017 at 8:31
  • <div class="progress-bar"></div> <script type="text/javascript"> $('.progress-bar').gradientProgressBar({ value: 0.75, size: 400, fill: { gradient: ["red", "green", "yellow"] } }); </script> this only I included in my html page, but here in script value like it is 0.75 I want to pass dynamic value which I am setting in my angular code as $scope.moodvalue. but if I am passing manual like here 0.75 its showing color change in status bar but when I am passing $scope.moodvalue which keeps changing, its not reflectin. Commented Feb 22, 2017 at 8:40
  • Carsten Løvbo Andersen- Thank you it worked for me. Commented Feb 22, 2017 at 10:32

2 Answers 2

0

use angular.element().scope() to get the values. and ng-change to update the value. refer this.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
    <script>
        function test() {
          var scope = angular.element($("#testInput")).scope();
          $(".test")[0].innerText = scope.test;
        }
        
        $(document).ready(function() {
          test();            
        });
        
    </script>
    <script>
    var app = angular.module('app', []);
    
    app.controller('myCtrl', function($scope) {
        $scope.test = '111';

        $scope.change = function() {
            test();
        }
    });
    </script>
</head>
<body>
    <div class="test"></div>
    <div ng-app="app">
    <div ng-controller="myCtrl">
        <input id="testInput" type="text" ng-change="change()" ng-model="test" />
    </div>
    </div>    
</body>
</html>

Sign up to request clarification or add additional context in comments.

2 Comments

Pengyy- Thank you it worked for me. But one solution will also work - if I move my script to angular code where I am getting my dynamic $scope.moodvalue.
@Piyu you can build a directive, put your processbar into it, and pass the $scope.moodvalue into directive by directive‘s parameter.
0

try this:

html:

<input type="test" ng-model="testValue"/>

javascript:

$('.progress-bar').gradientProgressBar({  
  value: $scope.testValue,
  size: 400,
  fill: {
      gradient: ["red", "green", "yellow"]
  }

});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.