是否可以在<p>属性上使用ngChange来刷新值

时间:2017-06-28 13:33:47

标签: angularjs

我正在使用'ngMaterial'模块进行对话。当用户点击编辑提示时,他可以编辑评论。一切正常,除非您在刷新页面之前没有看到评论更新。是否有可能让你看到变化? 这是我的提示函数,它将用户重定向到redirectEdit函数,该函数将更改放入数据库。

这些方法位于main.controller.js

$scope.showPrompt = function(ev,index) {
        var confirm = $mdDialog.prompt()
        .title('Edit your review')
        .placeholder('Review')
        .initialValue($scope.all[index].review)
        .targetEvent(ev)
        .ok('Okay!')
        .cancel('Cancel');

        $mdDialog.show(confirm).then(function(result) {
           $scope.redirectEdit(index,result);debugger;
        }, function() {
            $scope.status = 'You discarded changes.';
        });
    };




$scope.redirectEdit = function(index,result){debugger;
        $scope.all[index].id; console.log($scope.all[index].id);
        var JSONObject={
            "id":$scope.all[index].id,
            "name":$scope.all[index].name,
            "surname":$scope.all[index].surname,
            "email":$scope.all[index].email,
            "review":result
        }

        var Results = UniversalService.UpdateReview(JSON.stringify(JSONObject));
};

这是main.view.html中的按钮 <md-button ng-show="storageKey!==null" class="md-raised md-primary" ng-click="showPrompt($event,$index)" >Edit </md-button>

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

        <div class="col-md-8">
                <p>{{item.id}} Review posted by: {{item.name}}</p>           
                <p>{{item.review}}</p>
                <span uib-rating ng-model="rate" max=5  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>

1 个答案:

答案 0 :(得分:2)

您应该在review方法中更新已编辑元素的$scope.all[index].review = result;属性,例如scope.redirectEdit