How to put default value in an input type hidden in angularjs with ionic?

2

Good evening,

I have a mobile app, I'm submitting a form with a input type hidden but I want this input to have the value passed from another controller but I'm not able to pass since I tried ng-init but it does not work

Input

<input type="hidden" ng-model="input.estabelecimento">

Controller

.controller('SugerirCorrecao', function($scope, $http, sessionService) {
$scope.BtnSugerirCorrecao= function (input){
    $http.post("https://www.sabeonde.pt/api/api_sugerir_correcao.php?user_report=" + sessionService.get('nome') + "&telefone=" + input.telefone + "&morada=" + input.morada + "&encerrado=" + input.encerrado + "&menu=" + input.menu + "&detalhes=" + input.detalhes + "&estabelecimento=" + input.estabelecimento).success(function (data) {
        alert("A sua sugestão foi enviada com sucesso!");
        $scope.editar_perfil = data;
    }).
    error(function (data) {
        alert("Não foi possivel enviar a sua sugestão!");
    });
}

})

Controller of the title I want to pass

.controller('TitEstabelecimento', function($scope, $http, $stateParams) {
$http.get("https://www.sabeonde.pt/api/api_tit_estabelecimento.php?slug="+$stateParams.EstabelecimentoSlug).success(function (data) {
    $scope.tit_estabelecimento = data;
});

})

    
asked by anonymous 24.09.2015 / 21:49

1 answer

2

If you want to pass a variable from one Controller to another, I advise you to do this through a Service that you access by two.

Example:

First Controller:

'use strict';

angular.module('ngapp').controller('LoginController', function(global){

  this.user = global.info.user || null;
  this.password = null;
});

Service:

'use strict';

angular.module('ngapp').service('global', function(){

  this.info = {
    user: null
  };
});

Second Controller:

'use strict';

angular.module('ngapp').controller('MainController', function($rootScope, global, mainService, $state){

  if(global.info.usuer == null){
    $state.go('login');
  }
});
    
06.11.2015 / 20:45