Aditya Parsai Aditya Parsai - 9 months ago 32
AngularJS Question

Passing Data from view to contoller angularjs

I am passing a value through a function parameter in the view to the controller. Then i am storing that value in $scope. Then i am trying to access the same value through scope but in a different html page. But the value is not available. I am using UI-router for routing. Can anyone please tell what may be the cause for this?

this is the 1st page from which obj.roleId is being passed in the openwindow1 function to the controller.

<!DOCTYPE html>
<table class="table">
<thead align="center" class="thead-inverse">
Role Name
<div class="getSortClass('roleName')"></div>
Role ID
<div class="getSortClass('roleID')"></div>
<tr align="center">
<td><button class="btn btn-primary">Edit
User</button><button class=
"btn btn-primary">Delete</button></td>

and this the controller. i am storing the value in $scope.roleIdk:

.controller('UserRoleEdit', ['$compile', '$scope', '$window',
function($compile, $scope, $window) {
$scope.openWindow1 = function(roleID) {
'User Role
$scope.roleIDk = roleID;


Finally i am trying to access it in another html view:


But i cant access it.


If you are sharing it between views the scope will be different, so whatever you add in a view scope wont be present in the other.

You can store it in a Service. Services are singleton so they will be shared in all your views.

You can also store it on the browser local storage.

In you scenario you may want to pass it as a parameter on the URL though:

$'http://localhost:9000/#/homepage/userRoleEdit/' + roleID, User Role Edit', 'width=1300,height=1000');

You can then use the $routeParams service in the other view controller to access it.