簡體   English   中英

從角度控制器遞增JSON中的字段

[英]Incrementing a field in JSON from angular controller

我有一個包含如下字段的架構: flagCount : Number

當用戶單擊按鈕( reportListing按鈕)時,我試圖將計數增加1。 該按鈕位於HTML頁面內,如下所示:

  <img class="flagIcon" id="flag" src="../../../images/red_flag_icon.jpg" background-color=transparent ng-hide="hide" ng-click="reportListing()"/>

控制器相關部分:

app.controller('ListingController', function ($scope, $location, $http) {

    $scope.hide = false;
    $scope.reportListing = function() {
        $http.get("/api/listing/:street/:buildingNumber/:apartmentNumber").success(function (apartment){
            //var count = apartment.flagCount;
            sweetAlert("Thank you!", "This listing has been reported", "success");
            $scope.hide = true;
        });
    };

我嘗試了幾種方法,但是由於無法訪問flagCount來更新它而失敗了(是否只能通過后端(節點))?

如果要在前端使用節點,則該節點將必須發送帶有flagCount屬性的響應對象。 如果flagCount只是保存在數據庫中,則不需要使用get請求。

您可以改用發布請求。 發布請求對於更改數據庫信息很有用。

如果前端需要,Node可以使用flagCount進行響應。

如果確實需要flagCount,則檢查節點響應對象以查看它是否正在發送它。 如果在瀏覽器中使用了flagCount,則還可以將其保存並在角度服務中檢索它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM