无法访问ng-repeat angularjs在js中使用的结果

not able to access the results of the ng-repeat angularjs to use in js

本文关键字:结果 js 访问 ng-repeat angularjs      更新时间:2023-09-26

对不起,我是个新程序员。
这是我的html脚本

<li ng-repeat="friend in friends | filter:searchText"><a onclick="eraseText('{{friend.id_app}}')"  href="#"><i class="{{friend.icon}}" style=" padding:2px; color:{{friend.warna}}';"></i>{{friend.prog_name}}</a></li>

And This my js

function eraseText(id_app1) {
alert(id_app1);
document.getElementById("search-ac").style.display = "none";
var url = 'description_app.php';
var id_app = id_app1;
    $.post(url, {id_app: id_app} ,function(data) {
      $(".modal-body").html(data).show();
});}

我得到这个:结果

当你使用AngularJS时,你必须使用ng-clickng-href而不是onclickhref

你的代码应该是这样的:

<li ng-repeat = "friend in friends | filter:searchText">
    <a ng-click = "eraseText('{{friend.id_app}}')" ng-href = "<HTTP_LINK>">
        <i class = "{{friend.icon}}" style = " padding:2px; color:{{friend.warna}}';">
        </i>
        {{friend.prog_name}}
    </a>
</li>

您将参数作为字符串传递给函数eraseText(),这就是您获得此输出的原因。另外,使用角事件ng-click。将代码改为from -

onclick="eraseText('{{friend.id_app}}')"

 ng-click="eraseText(friend.id_app)"