[英]AngularJS Passing data from view to controller using Laravel PHP call
[英]Passing Data from view to controller angularjs
我正在通过视图中的功能参数将值传递给控制器。 然后,我将该值存储在$ scope中。 然后,我试图通过作用域但在不同的html页面中访问相同的值。 但是该值不可用。 我正在使用UI-router进行路由。 谁能告诉我这可能是什么原因吗?
这是obj.roleId在openwindow1函数中从中传递到控制器的第一页。
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<table class="table">
<thead align="center" class="thead-inverse">
<tr>
<th>
Role Name
<div class="getSortClass('roleName')"></div>
</th>
<th>
Role ID
<div class="getSortClass('roleID')"></div>
</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr align="center">
<td>{{obj.roleName}}</td>
<td>{{obj.roleID}}</td>
<td><button class="btn btn-primary">Edit
User</button><button class=
"btn btn-primary">Delete</button></td>
</tr>
</tbody>
</table>
</body>
</html>
这是控制器。 我将值存储在$ scope.roleIdk中:
.controller('UserRoleEdit', ['$compile', '$scope', '$window',
function($compile, $scope, $window) {
$scope.openWindow1 = function(roleID) {
$window.open(
'http://localhost:9000/#/homepage/userRoleEdit',
'User Role
Edit',
'width=1300,height=1000');
$scope.roleIDk = roleID;
alert($scope.roleIDk);
};
}
]);
最后,我试图在另一个html视图中访问它:
如果您在视图之间共享它,则范围将有所不同,因此您在视图范围中添加的任何内容都不会出现在另一个视图中。
您可以将其存储在服务中。 服务是单例的,因此它们将在您的所有视图中共享。
您也可以将其存储在浏览器本地存储中。
在您的情况下,您可能希望通过以下方式将其作为参数传递给URL:
$window.open('http://localhost:9000/#/homepage/userRoleEdit/' + roleID, User Role Edit', 'width=1300,height=1000');
然后,您可以在另一个视图控制器中使用$routeParams
服务来访问它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.