在范围内声明函数并稍后调用它

时间:2015-09-10 20:00:20

标签: javascript angularjs

调用callService函数失败。相反,除了“制作控制器......”之外,控制台中没有显示任何控制台消息。我正在使用指令ng-click =“callService()”来从HTML按钮进行调用。我是棱角分明的,有人能指出我正确的方向吗?代码如下。

(function() {
    console.log('making a controller....');
    'use strict';
    angular.module('myModule').controller('myController', myController);

    myController.$inject = ['$scope','$http'];


    function myController($scope, $http) {
        console.log("controller initialized...");

            $scope.callService = function(){
            console.log("callService called...");
            var urlSearchService = 'http://domain/proj/rs/stuff/moreStuff';
            var skuVal = $scope.skuField;
            var mVenVal = $scope.mVendorField;
            //need to somehow specifiy that xml is a @FormParam
            var xmlItemSearchRequest = "<ItemSearchRequest>"
                            +"<skuid>" + skuVal + "</skuid>"
                            +"<mvendor>" + mVenVal + "</mvendor>"
                        +"</ItemSearchRequest>";

            console.log('calling: ' + urlSearchService + 'sending xml: ' + xmlItemSearchRequest);
            $http.post(urlSearchService, xmlItemSearchRequest).
                success(function(data){
                    $scope.searchResults = data;
                    console.log('call to ' + urlSearchService + ", was a success.");
                }).error(function(data, status) {
                      console.error('Calling error', status, data);
                });
        };

    };
})();

0 个答案:

没有答案