separating information that is in string type in AngularJS

0

I have the following code:

app.controller("LoginCtrl", function ($scope, LoginAPI) {


    $scope.doLogin = function (model) {
        if (model.username === undefined || model.password === undefined) {
            return false;
        }

        LoginAPI.post(model).success(function (results) {
            localStorage.removeItem('token');
            //Armazena o token no localStorage
            localStorage.setItem('token', JSON.stringify(results));
            //pegando so o token
            console.log(results);


        })
        .error(function (Error) {
            console.log(Error);
        })

    };
});

variable results me returns the following information:

{**"access_token":"RBIuaO8f4xsSrEUgWoPA8w1EcuRW2U1vSIGiIzzCzsPwCibo1SHRtIYWZVfpFQmW17nzJ-hQsIE4wJBZpTfZi4_OYg1EMrCyEJwWg7nN4mq7-tGwKF8cDhMlruxKBa_lVzpoUBtSB1l0UfEXwb8a-PIsWJ6LGu7uG525xLy-5stVLdrbe3nh54iygNwdyY14GlBjbrBmnWxYzRJ_5UnA7klIk-DpW3vybll24RVMgD-nR1EI-ckdRPana-nySYsYNgElwq7PSQrSr2NHavZmyo-8vMT_BcGYYF5h9dWSZoSbaE8t8II2DaM2sZL-9KLS50SMBZ1N6oPsUv2D7uI3f1qM8EsK5GQ21tG-Lt3_DHwofE_aIKvmHo2CmFTd910HBSJpR63iwMwL-9VTOT6r98u85YWP6WZxGJWJFoMmY4ek0AEjDqbvn1QQOvGBlnJzJ4wfJtqBeEt_RAIubvmg-2tS4JMaAMC-oNz904dIk_3j1RzVfjQL9CtS8eYJNcjY"**,"token_type":"bearer","expires_in":1209599,"userName":"[email protected]",".issued":"Mon, 13 Mar 2017 18:11:11 GMT",".expires":"Mon, 27 Mar 2017 18:11:11 GMT"}

I need to transform this string set into an object and get the value of the token that is the access_token that is in bold. How do I solve this problem?

    
asked by anonymous 13.03.2017 / 19:18

1 answer

-1

Try this code:

var objeto = {};
objeto['access_token'] = JSON.stringify(results);
    
13.03.2017 / 21:26