How to pass data between forms in angular?

-3

Does anyone know how I can share data between form in angular? It happens that I have a table and when clicking on an id you must show me the detail of that id on another page, I am using this service to store the id but when redirecting me to the other page the id is lost

This is the code, sorry if this messy thing, I'm new using this tool

<div class="divPrincipal" ng-app="SolicitudesWeb" ng-controller="SeguimientoSolicitudesController as ctrl" >
        <div class="table-responsive">
            <table>
                <tr>
                    <td class="tamañoLetraTablaTitulo">ID</td>
                    <td class="tamañoLetraTablaTitulo">DESCRIPCIÓN</td>
                    <td class="tamañoLetraTablaTitulo">REGISTRADA</td>
                    <td class="tamañoLetraTablaTitulo">SOLICITADA</td>
                    <td class="tamañoLetraTablaTitulo">DENEGADA</td>
                    <td class="tamañoLetraTablaTitulo">AUTORIZADA</td>
                    <td class="tamañoLetraTablaTitulo">COTIZACIÓN</td>
                    <td class="tamañoLetraTablaTitulo">VISTO BUENO</td>
                    <td class="tamañoLetraTablaTitulo">CANCELADA</td>
                    <td class="tamañoLetraTablaTitulo">CONCLUIDA</td>
                </tr>
                <tr ng-repeat="x in ctrl.SegSolic">
                    <td><a ng-click="ctrl.param(x.IdUr)">{{x.IdUr}}</a></td>
                    <td>{{x.Descripcion}}</td>
                    <td>{{x.Registrada}}</td>
                    <td>{{x.Solicitada}}</td>
                    <td>{{x.Denegada}}</td>
                    <td>{{x.Autorizada}}</td>
                    <td>{{x.Cotizacion}}</td>
                    <td>{{x.VistoBueno}}</td>
                    <td>{{x.Cancelada}}</td>
                    <td>{{x.Concluida}}</td>
                </tr>
            </table>            
        </div>
    </div>
</div>

app.service('ServiceParametrosSolicitud', function () {
        var message = '';
        this.setMessage = function (msg) {
            message = msg;
            alert(message);
        }
        alert(message);

        this.getMessage = function () {
            return this.message;
        }
    })
    
    


app.controller('SeguimientoSolicitudesController', ['$scope','ServiceParametrosSolicitud', function ($scope, ServiceParametrosSolicitud) {
        this.SegSolic = "";
        this.SolicitudDetalle = "";
        this.Parametro = "";
        var self = this;

        solicitudContext.obtenerListaSegSolicitudes(function (resp) {
            switch (resp.ressult) {
                case "tgp":
                    self.SegSolic = solicitudContext.ListaSeguimientoSolicitudes;
                    break;
                case "notgp":
                    break;
                default:
                    break;
            }
            $scope.$apply();
        });

        this.param = function (Id) {            
            ServiceParametrosSolicitud.setMessage(Id);
            window.location.href = urlServer + "Home/About";
        };
    }]);
    
    
    
    

app.controller('SolicitudesController', ['$scope', 'ServiceParametrosSolicitud', function ($scope, ServiceParametrosSolicitud) {
        this.SolicitudDetalle = "";
        var self = this;
        
        var dependencia = ServiceParametrosSolicitud.getMessage();
        
        solicitudContext.obtenerListaSolicitudes(dependencia, function (resp) {
            switch (resp.ressult) {
                case "tgp":
                    self.SolicitudDetalle = solicitudContext.ListaSolicitudes;
                    break;
                case "notgp":
                    break;
                default:
                    break;
            }
            $scope.$apply();
        });
    }]);
    
asked by Rafa Rosales 28.11.2017 в 23:00
source

1 answer

2

Good afternoon would be this way I hope it works correctly, I help you friend are not forms in this case but drivers, but you understand: D

var App = angular.module('App', []);

App.controller('ControllerOne', ['$scope', 'MyService', function ($scope, MyService) {
    $scope.Method = function () {
        MyService.setVar($scope.inputValue);
    }
}]);

App.controller('ControllerTwo', ['$scope','MyService', function ($scope, MyService) {
     $scope.$watch(function () { return MyService.getVar() }, function () {
        $scope.newvar = MyService.getVar();   
    });
}]);

App.service('MyService', function () {
    var UseVar = '';
        return {      
        getVar: function () {
            return UseVar;
        }
        ,
        setVar: function (value) {
            UseVar = value;
        },    
    };
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="App">
  <div ng-controller="ControllerOne">
    <h2>Controller 1</2>
    <input ng-model="inputValue" />
    <input type="button" value="press" ng-click="Method()" />
  </div>
  
  <div ng-controller="ControllerTwo">
      <h2>Controller 2</h2>
    {{newvar}}
  </div>
</div>
    
answered by 28.11.2017 / 23:35
source