How to show json response to webpage?

I had a situation where when I press the button, the controller method is called. $ Http.get will give me the url as an answer. When I hit this url, I get bootstrap modal (all modal html) as an answer. I want to show that the modal response to the boot modal, which I have.

How can i do this?

Button:

<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>

Controller Code:

$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);
    });

Controller response from console.log statement:

<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>

Now I want this answer to appear as a boostrap modifier on another page. How can i do this?

+4
source share
1 answer
$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;
}
0
source

Source: https://habr.com/ru/post/1607930/


All Articles