Help get this topic noticed by sharing it on Twitter, Facebook, or email.

Passing scope variables between scope functions

Hello,

I need to pass data from a scope function to another scope function in the same screen.
1- I've defined the data model in the Project>Model.
2- Under my screen, I've created a scope variable using my Project data Model(created in step1);
3- Inside my function1, I call a create-user-database service, which -after success- returns and Id and SessionToken that I store in my scope variable (created in step2);
4- I call another function that contains a database-service to which I want to pass the Id and SessionToken (step3) but it seems that the passing of the values through the scope variable doesn't work.

I wonder what I'm missing in the process!
N.B : I tested the services seperatly through appery io builder interface and they worked. this is why I suspect that I'm not understading something correctly.

Could you please help me out!
1 person has
this question
+1
Reply
  • Hello Salim,

    Please see the answer in the ticket #29876
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited sad, anxious, confused, frustrated

  • Hello Serhii,

    Thank you for you answer.

    I'm afraid I'm missing something in the process because I didn't work. In a nutshell, here's what I have done:

    Step 1: Model Data

    I created (under Model Data) a variable called Globale with two propertises : UserId and SessionToken.

    Step 2 : Index Page
    I declared (under Index Page) a scope variable called globale of Type Globale.

    Step 3: My first Screen
    I call a service to create a user and, on success, I store the id and sessiontoken respectivily in the properties UserId and SessionToken of my global variable.
    The commands I used to store the id and sessiontoken are:

    $scope.globale.userId=success.data._id;
    $scope.globale.sessionToken=success.data.sessionToken;

    Step 4: Use upadate service.
    I update the user that I have created in the setep 3 using the code:
    var requestData = {};
    requestData.params = {};
    requestData.headers = {};
    requestData.data = {};
    requestData.params._id = $scope.globale.userId;
    requestData.headers['X-Appery-Session-Token'] = $scope.globale.sessionToken;

    PS: I've tried also the following lines in steps 3 and 4:
    step 3:
    var globale_scope=$scope.globale;
    _.set(globale_scope, 'sessionToken', success.data.sessionToken);
    _.set(globale_scope, 'userId', success.data._id);
    $scope.globale = globale_scope;
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited sad, anxious, confused, frustrated

  • Hi Serhii,

    I stumbled upon Angular factory as a solution. I tried it but yet no effect! is it relevant to use Angular factory for my need?

    PS: I'm a newbie, so my suggestions might be either stupid or genius hhhh...

    I'm looking forwards to hearing from you.
    Thanks
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited sad, anxious, confused, frustrated

  • Your steps 1-4 are correct. What is wrong with them?
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited sad, anxious, confused, frustrated

  • I found that, when I initialize the indexe variable, in the init() function of my screen, with specific user id and session Token that way : $scope.globale.userId="59e61d02a42893424a06ade2";
    $scope.globale.sessionToken="54b1f3d6-a0d8-4761-9c03-2694edd4b0c7";
    then this values are passed on to the scope function I desire. But they don't receive the values of the response of the database service. It seems to me that there is something wrong with the on-success part of the service in my app! (though the creation is ok since I can verify it on the database).
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited sad, anxious, confused, frustrated

  • Hi Serhii,

    Thank you very much for the suggestion useful.

    Actually, I found a different way to solve the challenge and which worked just great!

    When I create a user, I pass on the userId and sessionToken as parameters to the following scope function (that way-on success- $scope.updateUser(userId, sessionToken) ). And It worked!

    Thank you for being responsive and helpful. As I discover more and more, I'll sure get back to you for more help ;)
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited sad, anxious, confused, frustrated