Angularjs:如何获取modal的值并将其设置为当前页面
我有一个表,每行有一个用户名和角色输入框。我想做的是当用户单击每行中的打开模式按钮时。模态将显示,他可以选择自己喜欢的所有者级别。例如,他选择Angularjs:如何获取modal的值并将其设置为当前页面,angularjs,Angularjs,我有一个表,每行有一个用户名和角色输入框。我想做的是当用户单击每行中的打开模式按钮时。模态将显示,他可以选择自己喜欢的所有者级别。例如,他选择owner 1并单击按钮Get info。当前页面行将所有者1设置为ng model=“row.role”管理员将变为“所有者1或所有者2或所有者3” mymodal.controller('MainCtrl', function ($scope) { $scope.showModal = false; $scope.toggleModal = funct
owner 1
并单击按钮Get info
。当前页面行将所有者1
设置为ng model=“row.role”
管理员将变为“所有者1或所有者2或所有者3”
mymodal.controller('MainCtrl', function ($scope) {
$scope.showModal = false;
$scope.toggleModal = function (row) {
$scope.showModal = !$scope.showModal;
$scope.getInfo = function(item){
row.role = item.Owner
}
};
$scope.users = [{
'id': 1,
'username':
...
我的问题是我不知道如何将getInfo的值传递给我的ng模型。有人能帮我解决这个问题吗?谢谢
mymodal.controller('MainCtrl', function ($scope) {
$scope.showModal = false;
$scope.toggleModal = function (row) {
$scope.showModal = !$scope.showModal;
$scope.getInfo = function(item){
row.role = item.Owner
}
};
$scope.users = [{
'id': 1,
'username':
...
这是我的小提琴:
var mymodal = angular.module('mymodal', []);
mymodal.controller('MainCtrl', function ($scope) {
$scope.showModal = false;
$scope.toggleModal = function () {
$scope.showModal = !$scope.showModal;
};
$scope.users = [{
'id': 1,
'username': 'ady',
'role': 'Admin'
}, {
'id': 2,
'username': 'tiu',
'role': 'Admin'
}, {
'id': 3,
'username': 'ert',
'role': 'Admin'
}];
$scope.setRole = [{
'id': '1',
'Owner': 'Owner 1'
}, {
'id': '2',
'Owner': 'Owner 2'
}, {
'id':'3', 'Owner': 'Owner 3'
}];
$scope.getInfo = function(item){
alert(item);
}
mymodal.controller('MainCtrl', function ($scope) {
$scope.showModal = false;
$scope.toggleModal = function (row) {
$scope.showModal = !$scope.showModal;
$scope.getInfo = function(item){
row.role = item.Owner
}
};
$scope.users = [{
'id': 1,
'username':
...
我的小提琴中的示例代码:
var mymodal = angular.module('mymodal', []);
mymodal.controller('MainCtrl', function ($scope) {
$scope.showModal = false;
$scope.toggleModal = function () {
$scope.showModal = !$scope.showModal;
};
$scope.users = [{
'id': 1,
'username': 'ady',
'role': 'Admin'
}, {
'id': 2,
'username': 'tiu',
'role': 'Admin'
}, {
'id': 3,
'username': 'ert',
'role': 'Admin'
}];
$scope.setRole = [{
'id': '1',
'Owner': 'Owner 1'
}, {
'id': '2',
'Owner': 'Owner 2'
}, {
'id':'3', 'Owner': 'Owner 3'
}];
$scope.getInfo = function(item){
alert(item);
}
mymodal.controller('MainCtrl', function ($scope) {
$scope.showModal = false;
$scope.toggleModal = function (row) {
$scope.showModal = !$scope.showModal;
$scope.getInfo = function(item){
row.role = item.Owner
}
};
$scope.users = [{
'id': 1,
'username':
...
好的,首先,向控制器添加另一个变量
$scope.currentId=0;
mymodal.controller('MainCtrl', function ($scope) {
$scope.showModal = false;
$scope.toggleModal = function (row) {
$scope.showModal = !$scope.showModal;
$scope.getInfo = function(item){
row.role = item.Owner
}
};
$scope.users = [{
'id': 1,
'username':
...
然后更改“打开模式”按钮,如下所示单击:
<td> <button ng-click="toggleModal(row.id)" class="btn btn-default">Open modal</button></td>
$scope.toggleModal = function (cid) {
$scope.showModal = !$scope.showModal;
$scope.currentId=cid;
};
mymodal.controller('MainCtrl', function ($scope) {
$scope.showModal = false;
$scope.toggleModal = function (row) {
$scope.showModal = !$scope.showModal;
$scope.getInfo = function(item){
row.role = item.Owner
}
};
$scope.users = [{
'id': 1,
'username':
...
最后,getInfo
以这种方式更改:
$scope.getInfo = function(item){
alert(" id:"+item.id + "\r\n " + item.Owner);
$scope.users[$scope.currentId-1].role=item.Owner;
}
mymodal.controller('MainCtrl', function ($scope) {
$scope.showModal = false;
$scope.toggleModal = function (row) {
$scope.showModal = !$scope.showModal;
$scope.getInfo = function(item){
row.role = item.Owner
}
};
$scope.users = [{
'id': 1,
'username':
...
这是一把小提琴:
mymodal.controller('MainCtrl', function ($scope) {
$scope.showModal = false;
$scope.toggleModal = function (row) {
$scope.showModal = !$scope.showModal;
$scope.getInfo = function(item){
row.role = item.Owner
}
};
$scope.users = [{
'id': 1,
'username':
...
mymodal.controller('MainCtrl', function ($scope) {
$scope.showModal = false;
$scope.toggleModal = function (row) {
$scope.showModal = !$scope.showModal;
$scope.getInfo = function(item){
row.role = item.Owner
}
};
$scope.users = [{
'id': 1,
'username':
...
传入在ng repeat中选择的行,单击get info时将值调出
开放模态
mymodal.controller('MainCtrl', function ($scope) {
$scope.showModal = false;
$scope.toggleModal = function (row) {
$scope.showModal = !$scope.showModal;
$scope.getInfo = function(item){
row.role = item.Owner
}
};
$scope.users = [{
'id': 1,
'username':
...
您想在何处显示来自他单击的按钮的数据?我想在角色输入框中显示它。因此,您只想在警报框中显示项目的id和所有者?我将选中此项,并告诉您此项是否有效。:-)