TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
pradeep kumar
NA
32
7.6k
Passing value from controller to controller
Sep 23 2017 2:53 PM
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
Reply
Answers (
3
)
AngularJS code?
How to handle security in angularjs