I trying to Pass value from one controller to another controller using Factory,
I am trying based on this example http://www.c-sharpcorner.com/article/pass-data-from-one-page-to-other-using-factory-or-service-in-angularjs/
Below is the code im using
Html code:
- "myApp" ng-controller="Phy1Controller">
class="wtable">
"6" class="colspanth">Performance class="wth"> - Physician
class="wth"> - Brand Trx
class="wth"> - % Brand Trx Chg
class="wth"> - Brand Mkt shr
class="wth"> - brand Market shr Chg
class="wth"> - Mkt Volume
"tab in Phyperform"> class="wtd">"#" ng-click="open(tab.Physician_nm)"> {{tab.Physician_nm}} class="wtd"> {{tab.Brand_trx}} class="wtd"> {{tab.Brand_trx_chng}} class="wtd"> {{tab.Brand_mkt_shr}} class="wtd"> {{tab.Brand_mkt_shr_chng}} class="wtd"> {{tab.Mkt_volume}} - var app = angular.module("myApp", ['ui.router']);
- app.config(function ($stateProvider, $urlRouterProvider) {
- $urlRouterProvider.otherwise('/home');
- $stateProvider
- .state('ShowData', {
- url: '/ShowData',
- templateUrl: '../Pages/Show.html'
- })
- .state('EditData', {
- url: '/EditData',
- controller:'Editctrl',
- templateUrl: '../Pages/Edit.html'
- })
- });
- app.factory("Phyfactory", function () {
- var savedData = {};
- function set(data) {
- savedData = data;
- }
- function get() {
- return savedData;
- }
- return {
- set: set, get: get
- }
- })
- app.controller("myCtrl", function ($location) {
- alert('my')
- $location.path('/Showdata')
- });
- //app.controller("PhyController", function ($location) {
- // alert('hi');
- // //$location.path('/Showdata')
- //})
- app.controller('Phy1Controller', function ($scope, $http, $location,Phyfactory) {
- alert('WTF');
- $scope.Phyperform = [];
- $http.get('/Home/Get_Physician_Performance').then(function (d) {
- $scope.Phyperform = d.data;
- alert(JSON.stringify(d.data));
- $scope.open = function (name) {
- var message = name;
- console.log('Hcpname', message);
- Phyfactory.set(message);
- $location.url('/EditData');
- //window.location='/Htmlpages/Hcp_performance.html';
- }
- }, function (error) {
- alert('Failed');
- });
- });
- app.controller('Editctrl', function ($scope, $location, Phyfactory) {
- //Phyfactory.get();
- $scope.stud = Phyfactory.get();
- })
On ng-click its not redirecting to another page and i need to pass the value from Phy1Controller to Editctrl as well.
Quick help please
pradeep kumarPosted Sep 24, 2017, 5:25 AM
pradeep kumarPosted Sep 23, 2017, 4:36 PM
Hamid KhanPosted Sep 23, 2017, 3:36 PM