A
A
Abc Edc2014-12-22 07:48:34
Angular
Abc Edc, 2014-12-22 07:48:34

TypeError: object is not a function what does she climb finally what does she want from me?

angular
.module('starter', [])
.controller('UserCtrl', ['$scope', 'User', function($scope,  User) {
   $scope.regInfo = {}; 
   $scope.insert = function(){
   	User = new User ();
   	User.insert ($scope.regInfo);
     }
}]) 
.factory('User', ['$http', function($http) {  
     function User(UserData) {  
          if (UserData) {  
               this.setData(UserData); 
          }  
     };       
     User.prototype = {  
          setData: function(UserData) {  
               angular.extend(this, UserData);  
          },
      insert: function(regInfo){
         $http({method: 'GET', url: 'http://car.bleg.ru/api.php?class=get_session&method=register&car_name='+regInfo.carwash_name+'&car_average_check='+regInfo.car_average_check+'&car_address='+regInfo.car_address+'&car_tags='+regInfo.car_tags+'&car_st_time='+regInfo.car_st_time+'&carwash_cl_time='+regInfo.car_cl_time+'&carwash_pos='+regInfo.car_pos+'&email='+regInfo.email+'&passwd='+regInfo.passwd+'&passwd2='+regInfo.passwd2})
   			.success(function(data, status, headers, config) {
           alert(data);
                })
        .error(function(data, status) { 
                     alert('ошибка епте');
                });
        }
     };  
     return User; 
}]);

finally, I rolled the boys, so I’ll change the question . I stole from the
habr such an organization, and it works out once and then the error is shorter TypeError: object is not a
function
for this trip

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Romanov, 2014-12-22
@gleber1

You return a function in a factory, and this can only be done in a service. In a factry, only an object can be returned. That is, replace .factory('User' with .service('User' or vene an object rather than a function that becomes a class.

M
Mikhail Osher, 2014-12-22
@miraage

Ooo..... Unsee....

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question