Tech
Forums
Jobs
Books
Events
Videos
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
3
Answers
Passing value from controller to controller
pradeep kumar
7y
322
1
Reply
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:
<div ng-app=
"myApp"
ng-controller=
"Phy1Controller"
>
<table
class
=
"wtable"
>
<tr>
<th colspan=
"6"
class
=
"colspanth"
>Performance</th>
</tr>
<tr>
<th
class
=
"wth"
>
Physician
</th>
<th
class
=
"wth"
>
Brand Trx
</th>
<th
class
=
"wth"
>
% Brand Trx Chg
</th>
<th
class
=
"wth"
>
Brand Mkt shr
</th>
<th
class
=
"wth"
>
brand Market shr Chg
</th>
<th
class
=
"wth"
>
Mkt Volume
</th>
</tr>
<tr ng-repeat=
"tab in Phyperform"
>
<td
class
=
"wtd"
><a href=
"#"
ng-click=
"open(tab.Physician_nm)"
> {{tab.Physician_nm}}</a> </td>
<td
class
=
"wtd"
> {{tab.Brand_trx}} </td>
<td
class
=
"wtd"
> {{tab.Brand_trx_chng}} </td>
<td
class
=
"wtd"
> {{tab.Brand_mkt_shr}} </td>
<td
class
=
"wtd"
> {{tab.Brand_mkt_shr_chng}} </td>
<td
class
=
"wtd"
> {{tab.Mkt_volume}} </td>
</tr>
</table>
</div>
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
Post
Reset
Cancel
Answers (
3
)
Next Recommended Forum
AngularJS code?
How to handle security in angularjs