angularjs - How to transfer $scope.variables to controller? -


i building system have items listed in list variables

  1. title
  2. skills
  3. budget
  4. posted

i have modal opens when click on item in list. take current selected item , use variables in second modal controller? possible?

i thinking of using service cache data pulled database, dont know how display selected item , not every item in modal.

here controller list items:

app.controller('openprojectsctrl', ['$scope', '$http', 'projectsmodal', function ($scope, $http, projectsmodal) {    $http.get("http://localhost/app/controllers/php/getprojects.php")   .success(function (response) {     $scope.projects = response.projects;   });    $scope.showmodal = function() {       projectsmodal.deactivate();       projectsmodal.activate();   };      }]); 

modal controller(where want view selected variables):

app.controller('projectsmodalctrl', ['$scope', '$timeout', 'projectsmodal', function ($scope, $timeout, projectsmodal) {  var ctrl = this;  ctrl.closeme = function () {   projectsmodal.deactivate(); };  }]); 

yes can use variables of 1 controller inside controller using 2 methods

  1. create service communicate between them.
  2. use $rootscope.$broadcast

sample code

angular.module('myservice', []).service('msgbus', function() {         this.servicevalue= {};      }]); }); 

and use in controller this:

controller 1

angular.module('myservice', []).controller('ctrl1',function($scope, msgbus) {     $scope.sendmsg = function() {         msgbus.servicevalue='hello';     } }); 

controller 2

angular.module('myservice', []).controller('ctrl2',function($scope, msgbus) { $scope.checkvalue(){    alert( msgbus.servicevalue); } }); 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -