Asaf.e
Asaf.e

Reputation: 27

Angularjs adding service

Html page code:

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

controller:

$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;
            } );

            } );`

service:

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

when i load the html, there is an eror "angular.js:13424ReferenceError: Id is not defined at new (controller1.js:56)"

Someone can point my eror? before i did it without service and it worked just fine, so the ng-click successfuly transfer the coupon.couponId, now when i try to transfer all the server calling to a service, i get this eror. the controller1 js.56 is the 1st line of the controler code i wrote here.

Upvotes: 0

Views: 23

Answers (1)

sumair
sumair

Reputation: 386

You have to do it like this

$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;
              } );

             } );
}

Upvotes: 2

Related Questions