Javascript 使用ng选中值添加到链接

Javascript 使用ng选中值添加到链接,javascript,angularjs,Javascript,Angularjs,解释起来相当复杂,但我会尽力做到最好。我想实现的是,使用复选框值(这是我的ID),当其中一个(因为它们是列表中的项目,所以有很多)被选中时,我想使用该值并能够触发我的锚标记来编辑该项目 复选框本身 <td><input type="checkbox" value="item.iid" ng-checked="item.iid" id="item_{{item.iid}}"></td> 您应该使用ng click而不是ng checked,当用户单击时,您应该

解释起来相当复杂,但我会尽力做到最好。我想实现的是,使用复选框值(这是我的ID),当其中一个(因为它们是列表中的项目,所以有很多)被选中时,我想使用该值并能够触发我的锚标记来编辑该项目

复选框本身

<td><input type="checkbox" value="item.iid" ng-checked="item.iid" id="item_{{item.iid}}"></td>

您应该使用ng click而不是ng checked,当用户单击时,您应该将当前项标记为选中或未选中 下面的例子

<a href="#/edit/{{lastChecked}}"><div class="edit">Edit</div></a>
<td><input type="checkbox" value="item.iid" ng-checked="amIChecked(item.iid)" ng-click="checkMe(item.iid)" id="item_{{item.iid}}"></td>

我认为href不会解析{{item.iid},而是使用ngHref。当我把它放在表格中时,它就工作了,但是如果表格中的每一行都需要一个编辑按钮,它就会变得杂乱无章。通过这种方式,我尝试对所有行使用一个按钮,并将其与复选框组合,以便以后也可以删除它们。
var EditCtrl = function ($scope, $location, $routeParams, Item) {
    $scope.action = "Update";
    var id = $routeParams.editId;
    $scope.item = Item.get({ id: id });

    $scope.save = function () {
        Item.update({ id: id }, $scope.item, function () {
            $location.path('/');
        });
    };
};
<a href="#/edit/{{lastChecked}}"><div class="edit">Edit</div></a>
<td><input type="checkbox" value="item.iid" ng-checked="amIChecked(item.iid)" ng-click="checkMe(item.iid)" id="item_{{item.iid}}"></td>
var EditCtrl = function ($scope, $location, $routeParams, Item) {
    $scope.action = "Update";
    var id = $routeParams.editId;
    $scope.lastChecked = null;
    $scope.item = Item.get({ id: id });
    $scope.checkMe = function(id){
        if($scope.lastChecked=== id){
            $scope.lastChecked= null;
        }else{
            $scope.lastChecked= id;
        }
    };
    $scope.amIChecked = function(id){
        return $scope.lastChecked=== id;
    };
    $scope.save = function () {
        Item.update({ id: id }, $scope.item, function () {
            $location.path('/');
        });
    };
};