I am using this generator.
I have my user module:
require('angular/angular');
require('angular-ui-router');
angular.module('userModule', ['ui.router'])
.config(['$stateProvider', function($stateProvider) {
$stateProvider
.state('utenti', {
url: '/utenti',
templateUrl: 'src/utenti/views/utenti.tpl.html',
controller: 'RegistrationCrl',
})
.state('access', {
url: '/access',
templateUrl: 'src/utenti/views/access.tpl.html',
controller: 'AccessCtrl',
});
}])
.controller('RegistrationCrl', require('./controllers/registrationLogin'))
.controller('AccessCtrl', require('./controllers/access'));
In my RegistrationCrl I use a service to create a new member:
module.exports = function($scope, User, Member, $state, $location,$rootScope, $stateParams){
$scope.registration = function(form){
if(!form.$valid ){
console.log('input error');
return;
}
else{
console.log('valid form');
Member.create($scope.newMember,
function(data){
$state.go('access', data);
},
function(data){
console.log(data);
}
);
}
};
};
I would like to use that data in my next view related to the accessCtl. I don't want to use the id in my URL and using the $stateParams.
My access controller is:
module.exports = function($scope, User, Member, $state, $rootScope, $stateParams){
console.log($state);
console.log($stateParams);
};
In that console.log I don't find my object passed with $state.go.
You can $stateParams to pass data to next view. Add param in target route
$stateProvider
.state('utenti', {
url: '/utenti',
templateUrl: 'src/utenti/views/utenti.tpl.html',
params: { myParam: null},
controller: 'RegistrationCrl',
})
Pass data to next view
$state.go("utenti",{myParam:{"data":"data"}})
And get data in next controller
$scope.paramDetails=$stateParams.myParam;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With