i want access controller values service, how can access it. try access controller values using following code. the code here jsbin.com
<script> var app = angular.module('app', []) .controller("ctrl1",['$scope','svc',function($scope,svc){ $scope.fun1=function(){ svc.service_set(); alert(svc.txt1); alert(svc.txt2); } }]) .controller("ctrl2",['$scope','svc',function($scope,svc){ $scope.fun2=function(){ svc.service_set(); alert(svc.txt1); alert(svc.txt2); } }]). service("svc",function(){ var svc={}; svc.service_set=function() { //i want access controller values here svc.txt1=ctrl1.c1txt1; svc.txt2=ctrl2.c2txt1; } return svc; }) ; </script>
you should not use controllers inside service. services meant used container reusable logic. instead of calling controller service, call service methods controller
Comments
Post a Comment