如何将角度1模态服务转换为typescript angular 2?

时间:2017-10-02 13:41:16

标签: javascript angularjs typescript angular2-services

我真的想将以下代码转换为角度2.它是否包含了大量额外的逻辑?请注意这是如何简单直接的。

我有模态服务

angular.module('app').service('myModalService', function ($modal, $http, $filter, $document) {
this.QuestionModal = function (message, title, showButtonNoCancel, buttonYesOK, buttonNoCancel) {
        return $modal.open({
            backdrop: 'static',
            keyboard: false,
            templateUrl: 'Scripts/Services/questionModal.html',
            controller: function ($scope, $modalInstance) {
                $scope.vm = { Message: '', Title: title };
                $scope.vm.Message = message;
                $scope.YesOkButton = buttonYesOK;                
                $scope.ButtonNoCancel = buttonNoCancel;                
                $scope.ShowButtonNoCancel = function () {
                    return showButtonNoCancel;
                }
                $scope.Ok = function () {
                    $modalInstance.close(true);
                }
                $scope.Cancel = function () {
                    $modalInstance.dismiss('cancel');
                }
            }
        });
    };

我这样称它并获得返回值

 myModalService.QuestionModal("Do you want to delete the order?", 'Cancel Order', true, "Yes", "No").result.then(
            function () {
                 //handle yes function here
            },
            function () {
                //handle no function here
                return;
            });

0 个答案:

没有答案