如何在AngularJS引导模式中不使用$scope?

如何在AngularJS引导模式中不使用$scope?,angularjs,angular-bootstrap,Angularjs,Angular Bootstrap,我在控制器里有这个代码。我用它打开一个angularJS引导模式,并连接另一个控制器 这里有没有一种方法不能将$scope用于ok()和cancel()函数 $scope.deleteTest = (test: ITest) => { var self = this; var modalInstance = $modal.open({ templateUrl: '/app/tests/partials/deleteTest.ht

我在控制器里有这个代码。我用它打开一个angularJS引导模式,并连接另一个控制器

这里有没有一种方法不能将$scope用于ok()和cancel()函数

   $scope.deleteTest = (test: ITest) => {
        var self = this;
        var modalInstance = $modal.open({
            templateUrl: '/app/tests/partials/deleteTest.html',
            controller: ['$scope', '$modalInstance', 'testService',
                function ($scope, $modalInstance, testService: ITestService) {
                    $scope.ok = () => {
                        var self = this;
                        testService.deleteTest()
                            .then(
                                () => {
                                    $modalInstance.close();
                                });
                    };
                    $scope.cancel = () => {
                        $modalInstance.dismiss('cancel');
                    };
                }],
        });
    }

看起来您正在使用TypeScript,因此可以执行类似的操作

var modalInstance = $modal.open({
    templateUrl: '/app/tests/partials/deleteTest.html',
    controller: DeleteTest,
    controllerAs: 'ctrl'
});

//...

class DeleteTest {
    static $inject = ['$modalInstance', 'testService'];

    constructor(private $modalInstance, private testService: ITestService) {

    }

    ok() {
        this.testService.deleteTest().then(() => this.$modalInstance.close());
    }

    cancel() {
        this.$modalInstance.dismiss('cancel');
    }

}
deletetetest.html
中,您可以使用以下命令调用
ok()
方法

<button ng-click="ctrl.ok()">Ok</button>
Ok

看起来您正在使用TypeScript,因此可以执行类似的操作

var modalInstance = $modal.open({
    templateUrl: '/app/tests/partials/deleteTest.html',
    controller: DeleteTest,
    controllerAs: 'ctrl'
});

//...

class DeleteTest {
    static $inject = ['$modalInstance', 'testService'];

    constructor(private $modalInstance, private testService: ITestService) {

    }

    ok() {
        this.testService.deleteTest().then(() => this.$modalInstance.close());
    }

    cancel() {
        this.$modalInstance.dismiss('cancel');
    }

}
deletetetest.html
中,您可以使用以下命令调用
ok()
方法

<button ng-click="ctrl.ok()">Ok</button>
Ok