0

I have an user login..

this.logincheck = function(log) {           
          var parameter ={
                    "mail" :log.mail,
                    "password" :log.passwords
                    }  
            alert(JSON.stringify(parameter));
            $http({
                url: '---------',
               -----------
            }).success(function(data,status) {
            if(data.status=="success")  {   
                var sessionid = data.member.member_id; //Member JSON is defined below
                $state.go('dashboardsnewsucc.dashboardefault', {userid: sessionid}); // How to pass entire object to user dashboard
            }
            else{
                alert("Invalid Username or Password try again. !!!");
            }
            }); 
    };

I not only want member ID I want entire data present in the member.... I have the following controller :

.state('dashboardsnew', {
            abstract: true,
            url: "/dashboardsnew",
            templateUrl: "views/common/content-empty.html",
        })

        .state('dashboardsnew.dashboardefault', {
            url: "/dashboardefault",
            templateUrl: "views/userdashboard.html",
            data: { pageTitle: 'Hive Dashboard',specialClass: 'loginscreen-gray-bg' },           
        })

I have the following JSON data from web service.( After user logged in I get this JSON data).

{
  "member": {
    "member_id": 51,
    "first_name": "Deepak",
    "last_name": "Verma",
    "phone": 6886438910,
    "password": "sushil",
    "role": [
      {
        "role_id": 2,
        "name": "Society Admin"
      }
    ],
    "associated": []
  },
  "society": {
    "society_id": 10,
    "society_name": "Green Velley"
  },
  "status": "success",
  "message": "member data details !"
}

Above JSON data has to be displayed in login home page. While using normal angular JS I supposed to use this :

$http.get('http://192.168.1.7:8080/apartment//member/details/' + myParamtr).then(function(response) {
        $scope.myData = response.data.member;
}

In front end I supposed :

{{myData.user_name}} 
1
  • what's the issue? and where's user_name in your myData? Commented Apr 28, 2017 at 12:30

2 Answers 2

1

If you need to persist data from one state to another, in this case I recommend using an angular service: https://docs.angularjs.org/guide/services

You can create a memberService, set the member data to the service, redirect the user, and retrieve the member data from the service in your next controller.

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

2 Comments

Thanks for ur reply. The site you mentioned it may be temporary down.. Can you suggest me more. Or this is enough : w3schools.com/angular/angular_services.asp
That w3 article doesnt seem to explain it well. This article by John Papa (angular prodigy) explains it well: johnpapa.net/… Also a more hands on example: github.com/aaronksaunders/hu1/wiki/…
0
url : your json file location with respect to your index file.
 $http.get(url).success(function(response) { 
       $scope.myData = response.member; // Your member data
       $scope.myData1 = response.member.first_name; // Your member firstName
});

2 Comments

Thanks for reply. Am using Angular framework.. How to pass json object to the controller.?
"response" is your data of json, so by getting response means you are getting object of json in your controller.

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.