javascript - Passing data in between controller without help of url? -


i creating 2 page webapp using angularjs. json file is:

{     "data": [          { "name": "bhav", "id": 123             }, {"name": "bhavi", "id": 1234 }, {"name": "bhavk", "id": 1235 } ] } 

my app.js(routing file is):

myapp = angular.module('myapp', ['slickcarousel',   'ngroute',   'myappcontrollers',     'myappservices','swipeli' ]);  myapp.config(['$routeprovider',   function($routeprovider) {      $routeprovider.       when('/', {         templateurl: 'partials/home-page.html',         controller: 'profilelistctrl',     }).     when('/profile/:typeofprofile', {         templateurl: 'partials/profile-detail.html',         controller: 'profiledetailctrl'       }) }]); 

and 1st page(home-page.html) in given formate:

<div ng-repeat="data in data"> <a href="profile/myfriend">{{data.name}}</a> </div> 

and on 2nd page(profile-details.html) want id number of profile considering using http.get request pull data json file in controllers.

so please me fetch id or name of clicked profile without passing through url .

note: through ui-route link: angular ui router passing data between states without url didnt that.

as stated in comments, want use $state.go() pass data.using $state.go() pass params pretty simple well. need inject ui.router in application. have created 2 partial views show passing of params params passed header.html side.html.

your js below:

var app = angular.module('nested', ['ui.router']); app.config(function($stateprovider,$locationprovider, $urlrouterprovider) {   $urlrouterprovider.otherwise("/");   $stateprovider.state('top', {       url: "",       templateurl: "header.html",       controller: 'topctrl'     })     .state('top.side', {       url: '/app/:obj/:name',       templateurl: "side.html",       controller: 'filterctrl'     }) });  app.controller('topctrl', function($scope,$state) {           $scope.goitem = function(){             $state.go('top.side',{obj:441,name:'alex'});           };       });   app.controller('filterctrl', function($scope,$state) {   console.log(json.stringify($state.params));   $scope.params = $state.params;       }); 

here working plunker find need regarding views, controller , script:

http://plnkr.co/edit/m1qeyrmncwtefd6ftc4t?p=preview

i have provided methods pass $stateparams using both ui-sref , $state.go(). however, if want share data among controllers. see answer in question:
share data in angularjs


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -