【问题标题】:How to call a Angular function from a Webapi return如何从 Webapi 返回调用 Angular 函数
【发布时间】:2014-11-14 06:15:29
【问题描述】:

我在我的项目中使用 PDFSharp。我需要在保存文档后打开一个模式。打开模式的功能在 Angular 控制器中。我该怎么做?

WebApi 控制器

 // Save the document...
           const string filename = @"C:\Users\texas_000\Desktop\TexasExterior\TexasExterior\JobSetupPdfs\HelloWorld.pdf";

            document.Save(filename);
            // ...and start a viewer.
           // Process.Start(filename);
        }
        catch (Exception ex)
        {
            Debug.Print(ex.ToString());
        }
        return string.Empty;

打开Modal的功能

$scope.PrintPreviewModal = function () {
    $ekathuwa.modal({
        id: "PrintPreviewModal", contentStyle: "width:800px;heigth:400px",
        scope: $scope,
        templateURL: "ModalPrintPreview"
    });
}

【问题讨论】:

    标签: angularjs model-view-controller asp.net-web-api


    【解决方案1】:

    我不知道您是如何调用 WebApi 控制器的,但我想(因为您使用的是 Angular)您使用的是 Angular 的 $http 服务。

    如果是这样,只需在通话结束时打开 promise success 上的模态框:

    $http.get('/SaveTheDocumentWebApiAction').success(function (){
        $scope.PrintPreviewModal();
    });
    

    【讨论】:

      【解决方案2】:

      我假设您知道如何从您的 Angular 应用程序进行 API 调用。

      在您进行 api 调用并返回后,您想要执行 $scope.PrintPreviewModal()

      如果您使用 Promise,您将希望在收到 200 响应代码时执行的 Success 函数中执行此操作。我希望这会有所帮助。

       $scope.save = function () {
              save(params, success, error); //api call to save doc
          };
      
          var success = function () {
             $scope.PrintPreviewModal(); //open modal
          };
      
          var error = function () {
            //do something
          };
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-04-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多