2016-05-13 61 views
0

Html頁面代碼:Angularjs加入服務

ng-click="removeCoupon(coupon.couponId)" 

控制器:

$scope.removeCoupon=adminService.removeCoupon(Id) 
    .then(
      function(response) { 
       hide_all_and_show_one_insideTab('successLog'); 
      $scope.log = "Coupon Id# " + Id + " successfully removed."; 
      adminService.getCoupons() 
     .then(
      function(response) { 
       $scope.coupons = response.data; 
      }); 

      });` 

服務:

 this.removeCoupon = function(Id){ 
    return $http.get(baseURL+"admin/removeCoupon/"+Id); 
           }; 

當我加載的HTML,還有一個eror 「angular.js :13424ReferenceError:Id沒有被定義爲 at new(controller1.js:56)「

有人可以指出我的錯誤?之前,我沒有服務,它工作得很好,所以ng-click成功傳遞了coupon.couponId,現在當我嘗試將所有服務器調用到服務,我得到這個錯誤。 controller1 js.56是我在這裏寫的控制器代碼的第一行。

回答

2

你必須做這樣

$scope.removeCoupon = function(Id){ 
    adminService.removeCoupon(Id) 
    .then(
      function(response) { 
       hide_all_and_show_one_insideTab('successLog'); 
      $scope.log = "Coupon Id# " + Id + " successfully removed."; 
       adminService.getCoupons() 
      .then(
       function(response) { 
        $scope.coupons = response.data; 
       }); 

      }); 
} 
+0

它確實解決了我的問題,\ –

+0

非常感謝你! –

+0

謝謝!如果它的工作,然後接受我的回答 – sumair