Angular-ui-bootstrap 模态不显示传递给它的数据
Angular-ui-bootstrap modal not showing data passed to it
我正在尝试将一些模型数据传递到模态 window 打开时。它在 $http.post 成功和失败 then()
中都有一些不同的标题和按钮文本。我将多个数据传递给它,例如:
//.then(){...//same as below }
,function (response){
$scope.PostRespData = response.data.message || 'Rq Failed';
$scope.pn = $scope.PostRespData.substring(53,63);
//(status=400) response modal string
$scope.name = 'Hey there!';
//modal options
$scope.opts = {
backdrop: true,
backdropClick: true,
dialogFade: false,
keyboard: true,
templateUrl : 'alreadyexists.html',
controller : ModalInstanceCtrl,
resolve: {}
};
$scope.opts.resolve.item = function() {
return angular.copy({name:$scope.name, errmsg:$scope.PostRespData, num:$scope.pn}); // pass name to modal dialo
}
//open the modal and create a modal Isntance
var modalInstance = $uibModal.open($scope.opts);
var ModalInstanceCtrl = function($scope, $uibModalInstance, $uibModal, item) {
$scope.item = item;
$scope.ok = function () {
$uibModalInstance.close();
};
$scope.cancel = function () {
$uibModalInstance.close();
}
我的 HTML 模板看起来像
<div class="modal-header">
<h1>{{item.name}}</h1>
</div>
<div ng-controller="Nav" class="modal-body">
<p>{{item.errmsg}}
<a href="http://myserver.com/page.jsp?num="+{{item.num}}+"&c=y">View {{item.num}}</a>
</p>
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="ok()">Edit Current Details</button>
<button class="btn btn-warning" ng-click="cancel()">Edit {{item.num}}</button>
</div>
我得到了我的模式,我也得到了静态数据,但是传递给它的数据没有反映出来。我花了一整天的时间来完成这项工作。
编辑:添加当前输出图片。
请帮帮我!
正如@charlietfl 所指出的,这是一个提升问题。要使用上面的代码,请将 var ModalInstanceCtrl = func..
移到 $http
按钮的 ng-click
调用之外。
我正在尝试将一些模型数据传递到模态 window 打开时。它在 $http.post 成功和失败 then()
中都有一些不同的标题和按钮文本。我将多个数据传递给它,例如:
//.then(){...//same as below }
,function (response){
$scope.PostRespData = response.data.message || 'Rq Failed';
$scope.pn = $scope.PostRespData.substring(53,63);
//(status=400) response modal string
$scope.name = 'Hey there!';
//modal options
$scope.opts = {
backdrop: true,
backdropClick: true,
dialogFade: false,
keyboard: true,
templateUrl : 'alreadyexists.html',
controller : ModalInstanceCtrl,
resolve: {}
};
$scope.opts.resolve.item = function() {
return angular.copy({name:$scope.name, errmsg:$scope.PostRespData, num:$scope.pn}); // pass name to modal dialo
}
//open the modal and create a modal Isntance
var modalInstance = $uibModal.open($scope.opts);
var ModalInstanceCtrl = function($scope, $uibModalInstance, $uibModal, item) {
$scope.item = item;
$scope.ok = function () {
$uibModalInstance.close();
};
$scope.cancel = function () {
$uibModalInstance.close();
}
我的 HTML 模板看起来像
<div class="modal-header">
<h1>{{item.name}}</h1>
</div>
<div ng-controller="Nav" class="modal-body">
<p>{{item.errmsg}}
<a href="http://myserver.com/page.jsp?num="+{{item.num}}+"&c=y">View {{item.num}}</a>
</p>
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="ok()">Edit Current Details</button>
<button class="btn btn-warning" ng-click="cancel()">Edit {{item.num}}</button>
</div>
我得到了我的模式,我也得到了静态数据,但是传递给它的数据没有反映出来。我花了一整天的时间来完成这项工作。
编辑:添加当前输出图片。
请帮帮我!
正如@charlietfl 所指出的,这是一个提升问题。要使用上面的代码,请将 var ModalInstanceCtrl = func..
移到 $http
按钮的 ng-click
调用之外。