0

I'm new to Totaljs. I wrote a code which try to create user with PUT request with angular factory:

app.factory('User', function($resource) {
    return $resource('/register', null, {
        register: { method: 'post' }
    });
});

In my angular controller, when I click on register button this method run:

$scope.register = function() {
    $scope.user = new User({email: $scope.email, password: $scope.password});
    $scope.user.$register();
} 

After click on register button, in console I got this :

Failed to load resource: The network connection was lost.

This is my Totaljs controller:

exports.install = function(framework) {
    framework.route('/register', registerPage);
    framework.route('/register/', register, ['post']);
};

function registerPage() {
    var self = this;
    self.view('registerPage')
}

function register() {
    var self = this;
    console.log("run")
    // instead add new user I just return an existing user for test
    var User = MODEL('user').Schema

    User.find(function(err, docs) {
        self.json(docs);
    });

}

When I try it with jQuery's $.ajax It works fine! So what is the problem? Thanks

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Aryan
  • 2,675
  • 5
  • 24
  • 33

1 Answers1

0

I ask my question from Peter Širka, he mail this answer:

Hello, it's ok. I found a problem in route:

framework.route('/register', register, ['put', 'json']);

Aryan
  • 2,675
  • 5
  • 24
  • 33
  • Framework supports multiple methods in one route. Example: `framework.route('/register/', register, ['put', 'post', 'json'])`. Thanks. – Peter Sirka Nov 25 '14 at 13:47