thinkster-django-angular-tutorial icon indicating copy to clipboard operation
thinkster-django-angular-tutorial copied to clipboard

Chapter 4: registerSuccessFn does not work.

Open robotron2084 opened this issue 9 years ago • 1 comments

I am unsure because I do not fully understand scope in javascript, but the function registerSuccessFn does not seem to work for me.

The initial function:

  function registerSuccessFn(data, status, headers, config) {
    Authentication.login(email, password);
  }

This does work tho:

    function registerSuccessFn(data, status, headers, config)
    {
      Authentication.login(data.data.email, data.data.password);
    }

It seems either the email and password from registration should be somehow saved into the scope of the Authentication service for use later by registerSuccessFn() or the data.data property should be used.

robotron2084 avatar Jun 24 '16 00:06 robotron2084

The instructions in the tutorial that define that function say: Replace Authentication.register with the following so if you really replaced it, then you should have all the curly brackets and semi colons in the right place such that both registerSuccessFn and registerErrorFn are within the scope of the register function, which is a member of the Authentication service.

As noted on this page, it is super weird that javascript private functions have access to their containing function's scope even after the containing function (register) has returned, but it is true and used often in javascript. It works for me as written, and I even understand that the references to email and password are within the scope of the register function. But I do find it odd from a language point of view.

mcwp avatar Aug 17 '16 00:08 mcwp