1

What's wrong on this?

var modulo = angular.module('SWAApp', []);
modulo.controller('SWAAllocationController', ['$scope','$http', function RunSWAAllocation($scope,$http) {
    $scope.LaunchAllocation = function RunSWAAllocation($scope, $http) {
        $http.get('/MP3_SIOP/WS/SWAService.svc/PostSWAAllocation')
        .success(function (data) {
            pvt_BindHeaderData($scope, data);
            alert("SWA Allocation OK");
        })
        .error(function (data, status) {
            alert("Si è verificato un errore nel dei dati!")
        });
    }
}]);

and

<div class="row" ng-controller="SWAAllocationController">
        <button type="button" ng-click="LaunchAllocation()">Run Allocation </button> ...

This give me $http undefined (and also $scope)

Thank a lot for your help.

PS: Sorry if I miss something or made something wrong, this is my first question and I'm not skilled on AngularJS

3 Answers 3

3

Remove $scope and $http from method $scope.LaunchAllocation.

$scope and $http are dependencies that u imported in controller already and no need to add as parameters in method. You can directly use it. If you are using in method as parameters and passing nothing when you call it (from ng-click), obviously they both will be undefined.

$scope.LaunchAllocation = function() {
        $http.get('/MP3_SIOP/WS/SWAService.svc/PostSWAAllocation')
        .success(function (data) {
            pvt_BindHeaderData($scope, data);
            alert("SWA Allocation OK");
        })
        .error(function (data, status) {
            alert("Si è verificato un errore nel dei dati!")
        });
    }

Also you don't need to put the function name after function. You are calling the function $scope.LaunchAllocation and not the other one. So it actually not needed

Sign up to request clarification or add additional context in comments.

Comments

0

I believe $http in that context is undefined

$scope.LaunchAllocation = function RunSWAAllocation($scope, $http) {

replace with this ...

$scope.LaunchAllocation = function RunSWAAllocation() {

Comments

0

I think you should replace

$scope.LaunchAllocation = function RunSWAAllocation($scope, $http)

with

$scope.LaunchAllocation = function RunSWAAllocation()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.