AngularJS ui模态传递数据
AngularJS ui modal passing data
这是 ui-select
用户可以 select 一个选项:
<ui-select ng-model="state.selected" ng-change="openModal(state.selected,orders.order_id)" ng-if="orders.state == 'Paid'" theme="selectize" ng-disabled="disabled" style="width: 300px;"> .....
只要有变化,就会从bootstrap
触发模态
$scope.openModal = function(name,oid){
$scope.modalInstance = $modal.open({
templateUrl: 'reservationModal.html',
scope:$scope,
name: function(){
return name;
}
});
}
$scope.cancel = function(){
$scope.modalInstance.dismiss();
}
$scope.confirmChg = function(){
console.log('ok...');
}
模板如下:
<script type="text/ng-template" id="reservationModal.html">
<div class="modal-header">
<h3 class="modal-title">Confirmation</h3>
<!--<button class="btn btn-warning" ng-click="close()">X</button>-->
</div>
<div class="modal-body">
Confirm to change status to {{name}} ?
</div>
<div class="modal-footer">
<button class="btn btn-danger" type="button" ng-click="confirmChg(status_oid,status)">Yes</button>
<button class="btn btn-warning" type="button" ng-click="cancel()" data-dismiss="modal">No</button>
</div>
</script>
问题是,模板中的 {{name}}
没有显示。如何从开放模态函数传递变量?
您需要在作用域上设置名称,只需添加以下行:
$scope.name = name;
在调用 $scope.open 之前。所以 openModal 函数看起来像:
$scope.openModal = function(name,oid){
$scope.name = name;
$scope.modalInstance = $modal.open({
templateUrl: 'reservationModal.html',
scope:$scope,
name: function(){
return name;
}
});
}
这是 ui-select
用户可以 select 一个选项:
<ui-select ng-model="state.selected" ng-change="openModal(state.selected,orders.order_id)" ng-if="orders.state == 'Paid'" theme="selectize" ng-disabled="disabled" style="width: 300px;"> .....
只要有变化,就会从bootstrap
触发模态$scope.openModal = function(name,oid){
$scope.modalInstance = $modal.open({
templateUrl: 'reservationModal.html',
scope:$scope,
name: function(){
return name;
}
});
}
$scope.cancel = function(){
$scope.modalInstance.dismiss();
}
$scope.confirmChg = function(){
console.log('ok...');
}
模板如下:
<script type="text/ng-template" id="reservationModal.html">
<div class="modal-header">
<h3 class="modal-title">Confirmation</h3>
<!--<button class="btn btn-warning" ng-click="close()">X</button>-->
</div>
<div class="modal-body">
Confirm to change status to {{name}} ?
</div>
<div class="modal-footer">
<button class="btn btn-danger" type="button" ng-click="confirmChg(status_oid,status)">Yes</button>
<button class="btn btn-warning" type="button" ng-click="cancel()" data-dismiss="modal">No</button>
</div>
</script>
问题是,模板中的 {{name}}
没有显示。如何从开放模态函数传递变量?
您需要在作用域上设置名称,只需添加以下行:
$scope.name = name;
在调用 $scope.open 之前。所以 openModal 函数看起来像:
$scope.openModal = function(name,oid){
$scope.name = name;
$scope.modalInstance = $modal.open({
templateUrl: 'reservationModal.html',
scope:$scope,
name: function(){
return name;
}
});
}