Angularjs 是否可以从另一个控制器中的按钮触发按钮元素的ng点击?
我想使用Angularjs 是否可以从另一个控制器中的按钮触发按钮元素的ng点击?,angularjs,asp.net-mvc,Angularjs,Asp.net Mvc,我想使用角度模式进行CRUD操作,因此在ng controller=“ModalDemoCtrl”中,我们通过idmodalFire启动模式,这是我的模式: <div ng-controller="ModalDemoCtrl"> <script type="text/ng-template" id="myModalContent.html"> <div class="modal-header"> <
角度模式
进行CRUD操作,因此在ng controller=“ModalDemoCtrl”
中,我们通过idmodalFire
启动模式,这是我的模式:
<div ng-controller="ModalDemoCtrl">
<script type="text/ng-template" id="myModalContent.html">
<div class="modal-header">
<h3 class="modal-title">....</h3>
</div>
<div class="modal-body">
<form id="productForm" novalidate>
<div>
<label for="ProductName"> productName :</label>
<input type="text" name="ProductName" id="ProductName" ng-model="model.ProductName" value="" required />
</div>
<div style="margin:10px">
<label for="Price">price :</label>
<input type="text" name="Price" id="Price" ng-model="model.Price" />
</div>
</form>
</div>
<div class="modal-footer">
<button class="btn btn-primary" type="button" ng-click="Save()" ng-disabled="productForm.$invalid">save</button>
<button class="btn btn-warning" type="button" ng-click="cancel()">Cancel</button>
</div>
</script>
<button type="button" id="modalFire" class="btn btn-default modalBtn" ng-click="open()">UpdateProduct</button>
</div>
我有一个网格显示ProductList
:
<div ng-controller="ProductController" ng-init="GetAllProducts()">
<div class="row" style="margin-top:90px" ng-show="!ShowGrid">
<article class="widget">
<header class="widget__header">
<div class="widget__title">
<i class="pe-7s-menu"></i><h3>ProductList</h3>
</div>
<div class="widget__config">
<a href="#"><i class="pe-7f-refresh"></i></a>
<a href="#"><i class="pe-7s-close"></i></a>
</div>
</header>
<div class="widget__content table-responsive">
<table class="table table-striped media-table">
<thead style="background-color:rgba(33, 25, 36,0.1)">
<tr>
<th style="width:30%">price</th>
<th style="width:30%">productName</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="product in Products">
<td>{{product.Price}}</td>
<td>{{product.ProductName}}</td>
</tr>
</tbody>
</table>
</div>
</article>
</div>
</div>
价格
产品名称
{{product.Price}}
{{product.ProductName}
所以,我想为网格中可以触发模态的每一行添加一个
按钮
或元素
,有什么方法吗 除非我误解了你的问题,为什么不把按钮添加到你表格中的ng repeat
。例如:
<table class="table table-striped media-table">
<thead style="background-color:rgba(33, 25, 36,0.1)">
<tr>
<th>Price</th>
<th>ProductName</th>
<th>Edit</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="product in Products">
<td>{{product.Price}}</td>
<td>{{product.ProductName}}</td>
<td><button ng-click="loadItem(product)>Edit</button></td>
</tr>
</tbody>
</table>
$scope.loadItem = function(product){
var modalInstance = $modal.open({
animation: true,
templateUrl: 'myModalContent.html',
controller: 'ModalInstanceCtrl',
resolve: {
product: function () {
return product;
}
}
});
};
查看如何将产品传递到函数,然后使用resolve将产品传递到模式。在模态控制器中,您可以将产品附加到
$scope
,并像使用任何其他视图一样使用它。我想当我单击编辑时,模态出现。我照你说的做了,但是模态不起作用!我们会用小提琴来展示你的问题,否则我们就帮不了你了。
$scope.loadItem = function(product){
var modalInstance = $modal.open({
animation: true,
templateUrl: 'myModalContent.html',
controller: 'ModalInstanceCtrl',
resolve: {
product: function () {
return product;
}
}
});
};