C
C
Cyber_bober2017-03-28 17:37:32
Angular
Cyber_bober, 2017-03-28 17:37:32

What is the best way to organize data exchange between angular and node?

Hello, there was such a need, from one view we transfer data to the node, where they are processed and should be displayed in another view. Where is the best place to save this data, in the session?
Share your practices, I will be grateful.
Thank you.
I don't know why one of the answerers deleted the comment, but in general the architecture turned out to be suitable.
Node returns an object to the NG controller, and there we store the data in localstorage, thanks everyone.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Pavlyuchuk, 2017-04-06
@bort95

If you use ui-route you can use this (we have version 0.2.18):

//config.js
angular.module('module').config(function($stateProvider) {
    //...
    $stateProvider.state('create', {
        url: '/create',
        templateUrl: 'app/views/create.html',
        controller: 'someCtrl',
        controllerAs: 'someCtrl',
        pageTitle: 'somePage',
        params: {
            yourParametr: null, //dafault value
        },
    });
    //...
}

//someCtrl.js
//тут переход на нужную страницу, с передачей параметров, так же можно опусть передачу параметров
angular.module('module').controller('otherCtrl', function($state) {
    //...
    $state.go('create', {
        yourParametr: yourParametr
    })
    //...
}

on the someCtrl controller you will catch parameters in $stateParams.yourParametr
if you passed a parameter, then it will be there, if there was no parameter transfer, it will be null
https://ui-router.github.io/ng1/docs/0.2.18/index. ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question