0
我試圖在打開時將某些模型數據傳遞到模式窗口。它在一個$ http.post成功,也有失敗then()
與一些不同的標題和按鈕文本。我通過多個數據給它喜歡:Angular-ui-bootstrap模式不顯示數據傳遞給它
//.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>
我讓我的語氣和我也得到了靜態數據,但傳遞的數據給它沒有反映。我花了整整一天的時間來完成這項工作。
請幫幫我!
不會解決您的問題,但建議不要將事物分配給視圖中不需要的'$ scope'。 '$ scope.opts'可以簡單地爲'var modalOpts'。創建一個簡單的演示來重現問題。不容易看出爲什麼它現在不工作 – charlietfl
即使我不明白爲什麼它不起作用。我已經嘗試了很多,但都失敗了。我沒有在Chrome調試器中發現錯誤,但我認爲數據沒有傳遞給模態實例。我試圖直接在'resolve'中添加它,但是這並沒有改變任何東西。 –
'item'的注入必須正常工作,這意味着某些東西正在解決。當你記錄物品時,你在模態控制器內部的控制檯中獲得了什麼? – charlietfl