user122222
user122222

Reputation: 2419

Edit input after getting all data angular

I have function in my controller where I retrieve all my data from database (id,name,surname,emai,review):

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

then I print it like this in 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>

Now, I added edit and delete buttons for each review. But I am not sure how to actually edit specific review beause I need to have these values inside inputs and how to delete them. Is it possible when I printed my values with loadAll() ?

Upvotes: 0

Views: 126

Answers (1)

Rabbi Shuki Gur
Rabbi Shuki Gur

Reputation: 1716

By using the $index.

In you 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>

Then in your controller:

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

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

Upvotes: 1

Related Questions