Nam*_*nde 12 javascript angularjs angular-ui-bootstrap
我正在使用角度bootstrap ui模式框,它说为新控制器提供一个新的$ modalInstance.我想使用相同的控制器,我已经初始化模态框.我搜索但没有成功.我发现这个链接但没有成功 -
如何在Angular UI Bootstrap中为模态和非模态形式使用相同的控制器? Angular-ui bootstrap模式,无需创建新控制器
app.controller('UserCtrl',['$scope','$filter','ngTableParams','$modal',function($scope, $filter, ngTableParams,$modal) {
var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
controller: 'ModalInstanceCtrl', //Instead of this i want to use the same controller 'UserCtrl'
size: size,
resolve: {
items: function () {
return $scope.items;
}
}
});
modalInstance.result.then(function (selectedItem) {
$scope.selected = selectedItem;
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
};
};
} ]);
Run Code Online (Sandbox Code Playgroud)
这样我就可以在同一个控制器上调用save函数,该控制器在保存单击模态框时调用
Saj*_*kar 21
有可能在旧版本的UI-Bootstrap 0.10.0 下载 Library.Even最新版本,它适用于我
<!-- if you are using Bower -->
<script src="bower_components/angular-bootstrap/ui-bootstrap.min.js">
</script>
<script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js">
</script>
<!-- button click opens modal-->
<button ng-click="openModal()">Button test</button>
<!-- modal -->
<!-- look at 'type' and 'id' values -->
<script type="text/ng-template" id="myTestModal.tmpl.html">
<div class="modal-header">
<h3>Modal Header</h3>
</div>
<div class="modal-body">
<p>Modal Body</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" ng-click="close()" data-dismiss="modal">Close
</button>
<button type="button" class="btn btn-primary" ng-click="doSomething()">Do Something
</button>
</div>
</script>
Run Code Online (Sandbox Code Playgroud)
$scope.openModal=function(){
$scope.modalInstance=$modal.open({
templateUrl: 'myTestModal.tmpl.html',
scope:$scope
});
}
$scope.close=function(){
$scope.modalInstance.dismiss();//$scope.modalInstance.close() also works I think
};
$scope.doSomething=function(){
//any actions to take place
console.log("Do Something");
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9437 次 |
最近记录: |