angularjs - Pass data through $state.go and how to access it -


now need switch view using $state.go, need pass data in it. (i perfer pass object) searched on line help, didn't see answer fit question. here code:

state('editreport', {         url: '/editreport/:reports',         templateurl: 'submitter/editreport/editexpensesreport.html'     }) 

in ctr1:

$scope.goeditpage = function(report){                              $state.go('editreport',{'reports':report});                         } 

when user fire goeditpage . take them 'editreport' page.and in editreport page, have controller called 'ctr2', try access data this:

controller('ctr2',         [ '$scope','$stateparams', function($scope,$stateparams) {             $scope.lin = $stateparams.reports;             console.log($scope.lin);         } ]) 

but didn't work out, idea? , question how make data optional? because user may enter data or not, take them page.

a way pass data through query string, $state.go('state-name', {name:'fizz', tag: 'stackoverflow'})

on state needs this:

$stateprovider.state('editreport', { url: '/editreport/:reports?name=&tag', templateurl: 'submitter/editreport/editexpensesreport.html' })

on controller need retrieve information, can use $location that, this:

var myparams = $location.search(); //$location.search() returns object myparams = {name: 'fizz', tag: 'stackoverflow'} after copying parameters can delete them url with: $location.search({});


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -