1

I have implememnted a controller using angular js and type script using dot net nuke 7.and trying to call my web api method using http.put but getting error in status as 400. Here is my controller code:-

var customerapp = angular.module('CustomerSearch');
module CustomerSearch.controllers
{
    export class CustomerCtrl {
        static $inject = ['$scope', '$http', '$templateCache'];
        debugger;
        constructor(protected $scope: ICustomerScope,
            protected $http: ng.IHttpService,
            protected $templateCache: ng.ITemplateCacheService) {
            $scope.search = this.search;
            console.log(angular.element($scope).scope());
        }
        public search = (search: any) => {
            debugger;
           var Search = {
                ActId: search.txtAct,
                checkActiveOnly: search.checkActiveOnly,
                checkParentsOnly: search.checkParentsOnly,
                listCustomerType: search.listCustomerType
            };

            this.$scope.customer = [];
            this.$scope.ticket = [];
            this.$scope.services = [];


            this.$http.put('<%=ResolveUrl("~/API/Search/PutDoSearch")%>', Search).
                success((data, status, headers, config) => {
                debugger;
                this.$scope.cust_File = data[0].customers;
                this.$scope.ticket_file = data[0].tickets;
                this.$scope.service_file = data[0].services;
            }).
                error((data, status) => {
                debugger;
                console.log("Request Failed");
                alert(status);
                });

        }
    }
    var customerapp = angular.module("CustomerSearch", []);
    customerapp.controller('CustomerCtrl', CustomerSearch.controllers.CustomerCtrl);
}
Shian JA
  • 848
  • 4
  • 15
  • 52

2 Answers2

1

You should get rid of

this.$http.put('<%=ResolveUrl("~/API/Search/PutDoSearch")%>', Search)

And instead use:

this.$http.put("/API/Search/PutDoSearch", Search)
Orel Eraki
  • 11,940
  • 3
  • 28
  • 36
1

You need have the server parse <%=ResolveUrl("~/API/Search/PutDoSearch")%> for you.

One way you can do this put in a script tag e.g.

<script>
       var doSearchUrl = '<%=ResolveUrl("~/API/Search/PutDoSearch")%>';
</script>

Then within your typescript have

// At the root of your file
declare var doSearchUrl:string; 

// And later
this.$http.put(doSearchUrl, Search)
basarat
  • 261,912
  • 58
  • 460
  • 511
  • hello barsat thanx for your time but where i have define these script on my view page or where, and about declaration as well i tried to do the same in my controller and declare it at last where i have defined my angular app but it gives me error of "Undefined" – Shian JA Jun 03 '15 at 11:16