如何在JavaScript函数中使用角度变量作为参数

时间:2021-04-10 00:37:44

I'm trying to use an angular variable as a JavaScript parameters like this:

我正在尝试使用角度变量作为这样的JavaScript参数:

 <li ng-repeat="link in Links">
    <button data-icon="gear" data-role="button" data-iconpos="right" type="button" id="bitrate_btn_{{ link.Code }}" class="bitrate_btn btn" onClick="play_live_ind({{link.Code}});">
        {{ link.Title }} ( {{ link.Bitrate }} Kbps )
    </button>
 </li>

As you can see I'm calling a method called play_live_ind like this:

正如您所看到的,我正在调用一个名为play_live_ind的方法,如下所示:

play_live_ind({{link.Code}});

It's not working, as the page loads it exactly prints play_live_ind({{link.Code}});

它不起作用,因为页面加载它正好打印play_live_ind({{link.Code}});

How can I pass the value of link to this JavaScript function?

如何将链接值传递给此JavaScript函数?

This is a jw-player function that I can't rewrite it in angular because it has many function call on itself. So I need to call this function in javascript

这是一个jw-player函数,我不能用angular重写它,因为它本身有很多函数调用。所以我需要在javascript中调用此函数

So I just need a solution to pass the angular variable value to the Javascript function

所以我只需要一个解决方案将角度变量值传递给Javascript函数

1 个解决方案

#1


2  

Use ng-click instead of onClick, and define play_live_ind in your $scope.

使用ng-click而不是onClick,并在$ scope中定义play_live_ind。

//html
ng-click="play_live_ind(link.Code)";

//js
$scope.play_live_ind = function(inputs) { 
                          // function body 
                       }

#1


2  

Use ng-click instead of onClick, and define play_live_ind in your $scope.

使用ng-click而不是onClick,并在$ scope中定义play_live_ind。

//html
ng-click="play_live_ind(link.Code)";

//js
$scope.play_live_ind = function(inputs) { 
                          // function body 
                       }