javascript - How to pass parameters to a controller when using route? -
in application, loading views using ngroute,
.state('reportviewer', { url: "/reportviewer", controller: 'reportviewercontrol', templateurl: "views/report_viewer.html" })
i have search panel users can search reports, , when selecting report, should route different page , load report inside iframe. here code when user select report,
$scope.goreport = function(report){ $state.go('reportviewer'); }
i have defined constant in config changes dynamically based on report selection
.constant('digin_reportviewer','http://192.226.192.147:8080/api/repos/%3ahome%3aadmin%')
here need pass 'report' variable reportviewercontrol
when user select report,
here reportviewercontrol
routerapp.controller('reportviewercontrol', ['$scope', '$routeparams','digin_reportviewer',function($scope, $routeparams,digin_reportviewer) { //here need append report url , $scope.reporturl = digin_reportviewer+routeparams.report ; $scope.trustsrc = function(src) { return $sce.trustasresourceurl(src); } } ]);
you using ui-router confiuring routes ,but below in reportcontroller using $routeparams.i hope have use $stateparams that.
routerapp.controller('reportviewercontrol', ['$scope', '$stateparams','digin_reportviewer',function($scope, $stateparams,digin_reportviewer) { //here need append report url , $scope.reporturl = digin_reportviewer+stateparams.report ; $scope.trustsrc = function(src) { return $sce.trustasresourceurl(src); } } ]);
also have pass params url or in method this
.state('reportviewer', { url: "/reportviewer", controller: 'reportviewercontrol', templateurl: "views/report_viewer.html", params: ['report'] })
then can navigate so:
$scope.goreport = function(report){ $state.go('reportviewer', { 'report':'monthly' }); }
or:
var result = { 'report':'monthly' }; $state.go('reportviewer', result);
Comments
Post a Comment