Using angularjs route how can I get a scope value into another controller? -
i have project single page application.so using angular js route. in first controller have $scope value.the same value have use in other controller
here controller.js file
var module = angular.module("sampleapp", ['ngroute']); module.config(['$routeprovider', function($routeprovider) { $routeprovider. when('/route1', { templateurl: 'http://localhost/myfirstapp/welcome', controller: 'routecontroller1' }). when('/route2', { templateurl: 'http://localhost/myfirstapp/result', controller: 'routecontroller2' }). otherwise({ redirectto: '/' }); }]); module.controller("routecontroller1", function($scope) { $scope.value="athira" }) module.controller("routecontroller2", function($scope) { $scope.text=$scope.value + "sandeep" })
in result page should show 'athira sandeep'
thank kind of help
use service share data among controllers . option event emitters not fan because populates rootscope (in case) lot of events.
what it
angular.module('app',[]) .factory('sharedscope',function(){ var fac = this; var scope = ""; var sharedscope = { getscope : function(){ return fac.scope; }, setscope: function(scope){ fac.scope = scope } }; return sharedscope; }) .controller('ctrl1',function('sharedscope'){ sharedscope.setscope("angular"); }) .controller('ctrl2',function('sharedscope'){ var data = sharedscope.getscope(); $scope.text = data + " awesome"; //would angular awesome });
hope helps.
Comments
Post a Comment