2015-09-17 19 views
4

我有一種情況,當我點擊按鈕控制器方法被調用。 $ http.get會給我一個URL作爲迴應。當我打這個網址時,我得到引導模式(所有的模態html)作爲響應。我想將模態響應顯示到我擁有的引導模式中。如何將json響應顯示回網頁?

我該怎麼做?

按鈕:

<button type="button" class="btn btn-primary" data-target="#pwdConfirm" ng-click="doMethod('ResetPassword',@Model.Id)"><span class="col-sm-12 fa fa-refresh"> Reset Password</span></button> 

控制器代碼:

$scope.doMethod = function (method, Id) { 
    var userId = Id; 
    var url = "http://" + $window.location.host+ "/User/" +method+"?id=" + userId; 
    //var url = $window.location.host + "/User/" + method + "?id=" + userId; 
    $http({ 
     method: 'GET', 
     url: url    
    }).success(function (response) {    
     $scope.successresponse = response; 
     console.log(response); 

    }).error(function (response) { 
     alert(response); 
    }); 
從的console.log語句

控制器響應:

<div class="modal-dialog"> 
<div class="modal-content"> 
    <div class="modal-header"> 
     <button type="button" class="close" data-dismiss="modal">&times;</button> 
     <h4 class="modal-title">Password Reset</h4> 
    </div> 
    <div class="modal-body"> 
     <div class="col-md-12"> 
      <img src="/Content/images/greenCheck.png" title="logo" class="imgLogo" /> 
     </div> 
     <div class="col-md-12"> 
      <p>Password Reset to Default</p> 
     </div> 
    </div> 
    <div class="form-group"> 
     <div class="control-label col-md-4"></div> 
     <div class="col-md-8"> 
      Password : bforce 
     </div> 
    </div> 
    <div class="modal-footer"> 
     <div class="col-md-6 row"> 
      <a class="page-header fa fa-edit btn btn-warning" href="/User/Index" style="color:white">Activate later</a> 
     </div> 
    </div> 
</div> 

現在我想這個迴應是sh自己作爲另一個頁面中的助推模式。我怎樣才能做到這一點 ?

+2

向我們展示一些代碼,來自請求的內容是什麼?你嘗試了什麼? –

+0

https://docs.angularjs.org/api/ng/service/$http。基本上,你調用$ http,並定義一個回調函數...在回調,你可以做一些像$ scope.data = response.data –

+0

我回復了詳細的代碼,你可以看到那裏 – Sreelatha

回答

0
$scope.doMethod = function (method, Id) { 
    var userId = Id; 
    var url = "http://" + $window.location.host+ "/User/" +method+"?id=" + userId; 
    //var url = $window.location.host + "/User/" + method + "?id=" + userId; 
$http({ 
    method: 'GET', 
    url: url    
}).success(function (response) {    
    $scope.successresponse = response; 
    console.log(response); 
    var showBadRoleModelInstance = $modal.open({ 
     template: "<div ng-bind-html='htmlContent'></div>", 
     backdrop: true, 
     windowClass: 'modal', 
     controller: modalController, 
     resolve: { 
      htmlContent: function() { 
       return response; 
      } 
     } 
    }); 
}).error(function (response) { 
    alert(response); 
}); 



function modalController(htmlContent){ 
    $scope.htmlContent = htmlContent; 
}