Ad

Pass AngularJS Value / Variable Inside Javascript

- 1 answer

Here is my Angular data (i write here only one data entry as demo, actually i have so many entry):

var font = angular.module('font', []);

font.controller('fontListCtrl', function($scope) {

  $scope.font = [
                     {
                        id: "_001",
                        name: "Kalpurush",
                        download: "1"
                      }
                ]

    var download = scope.font.download
});

I want to pass my download ID into inside javascript inside html. but i cannot success.

<div class="fontbox" ng-repeat="font in font">
{{font.name}}
<script>ccount_display('download')</script>
</div>

Please help me, thank you :)

Ad

Answer

I am making some assumption based on your code/question. If that's not the case, I can modify my solution. There are couple of issues in your code. I've tried to fix them below:

var font = angular.module('font', []);
font.controller('fontListCtrl', function($scope) {
  $scope.fonts = [{
                    id: "_001",
                    name: "Kalpurush",
                    download: "1"
                  }];
     //assuming you're accessing above scope variable, your code had 'scope' but not $scope. And it's an array.
     $scope.download = $scope.fonts[0].download;
     //assuming you want to use download variable in your HTML.
});

Also the HTML is incorrect. You should do something like below:

ng-repeat="font in fonts"

Ad
source: stackoverflow.com
Ad