AngularJS ng-repeat 中的指令未传递评估值

AngularJS directives inside ng-repeat not passing evaluated value

我两天前才开始学习 AngularJS,所以如果您认为我没有以 Angular 的方式处理这个问题,请指导我。 所以下面的代码是我的 HTML 的一部分,它有 ng-repeat 指令

<div class="row" data-ng-repeat="button in buttons" ng-if="$index % 3 == 0">
   <div class="col-lg-3 col-lg-offset-1">
      <button class="btn btn-default button-width" data-ng-click="my_func('{{buttons[$index].desc}}')">{{buttons[$index].name}}</button>
   </div>
   <div class="col-lg-3 col-lg-offset-1">
      <button class="btn btn-default button-width" data-ng-click="my_func('{{buttons[$index + 1].desc}}')">{{buttons[$index + 1].name}}</button>
   </div>
   <div class="col-lg-3 col-lg-offset-1">
      <button class="btn btn-default button-width" data-ng-click="my_func('{{buttons[$index + 2].desc}}')">{{buttons[$index + 2].name}}</button>
   </div>
</div>

以下代码是我的 Angular 控制器,它将值传递给 HTML 中的 ng-repeat 指令,然后调用 HTML 中的 ng-click 指令控制器中的 my_func 函数。

remote_app.controller("remote-controller", function($scope, $http) {
    $scope.buttons = [{
        "desc": "OFF_V1",
        "name": "OFF",
    }, {
        "desc": " ",
        "name": " ",
    }, {
        "desc": "SOURCE_1",
        "name": "SOURCE",
    }];
    $scope.my_func = function(command) {
        $http.get("http://localhost:1337?comm=" + command).success(function() {
            $scope.result = "Sent to server - " + command;
        });
    };
})

现在,当呈现 HTML 页面时,这会显示数组中的值,但是当我单击调用 ng-click 指令的按钮并依次 my_func 时,发送的值发送到服务器的不是 my_func('OFF_V1') 的渲染值,而是发送的值 my_func('{{buttons[$index].desc}}')。我试图找到一个解决方案,但现在 $apply 和 $digest 之类的东西超出了我对 Angular 的理解,因此我们不胜感激。

如果你在没有 '' 的情况下通过,那么你将获得值,因为 angular 会将他的表达式解析为值。但在使用 '' angular 后会将其视为字符串,然后停止解析。如果您想发送值,请尝试在没有 '' 的情况下使用,但建议不要使用 angular 表达式({{}})传递任何一种方式,值都会被传递

像这样尝试

data-ng-click="my_func(buttons[$index].desc)"