获取所有数据角度后编辑输入

时间:2017-06-27 11:50:23

标签: angularjs

我在我的控制器中有功能,我从数据库中检索所有数据(id,name,surname,emai,review):

function loadAll() {
        UniversalService.GetAll()
            .then(function (a) {
                $scope.all=a;
            });
    }

然后我在html中打印它:

<div class="row comment-table" ng-repeat="item in all ">
        <div class="col-md-1">
            <img ng-src="http://www.gravatar.com/avatar/{{hash[$index]}}" alt="Description" />
        </div>

        <div class="col-md-9">
                <p>Review posted by: {{item.name}}</p>           
                <p>{{item.review}}</p>
                <span uib-rating ng-model="rate" max=5 on-hover="hoveringOver(value)" on-leave="overStar = null" titles="['one','two','three']" aria-labelledby="default-rating"></span>
                <span class="label" ng-class="{'label-warning': percent<30, 'label-info': percent>=30 && percent<70, 'label-success': percent>=70}" ng-show="overStar && !isReadonly">{{percent}}%</span>
        </div>



    </div>

现在,我为每个评论添加了编辑和删除按钮。但我不确定如何实际编辑特定的审查因为我需要在输入中包含这些值以及如何删除它们。我可以用loadAll()打印我的值吗?

1 个答案:

答案 0 :(得分:1)

使用$index

在你的HTML中:

<div class="row comment-table" ng-repeat="item in all ">
    <div class="col-md-1">
        <img ng-src="http://www.gravatar.com/avatar/{{hash[$index]}}" alt="Description" />
    </div>

    <div class="col-md-9">
        <p>Review posted by: {{item.name}}</p>           
        <p>{{item.review}}</p>
        <button ng-click="edit($index)">Edit</button>
        <button ng-click="delete($index)">Delete</button>
    </div>
</div>

然后在你的控制器中:

$scope.edit = function(index) {
    $scope.all[index] = // Your logic here.
};

$scope.delete = function(index) {
    $scope.all[index] = // Your logic here.
};