angularjs - How to transfer $scope.variables to controller? -
i building system have items listed in list variables
- title
- skills
- budget
- 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
- create service communicate between them.
- 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
Post a Comment