Angularjs 如果$q和$rootScope com来自不同的喷油器,则解决角度测试中的承诺

Angularjs 如果$q和$rootScope com来自不同的喷油器,则解决角度测试中的承诺,angularjs,promise,Angularjs,Promise,我有一个有趣的问题,所有有棱角的忍者在那里。你们中有人能解释一下为什么一个注入器注入的$rootScope服务不能用另一个注入器的$q服务创建的$apply/$digest来解析承诺吗 这可以通过使用typescript编写的以下测试进行复制: describe("TestInjection", () => { let rootScope1 : angular.IRootScopeService; let q1 : angular.IQService; let r

我有一个有趣的问题,所有有棱角的忍者在那里。你们中有人能解释一下为什么一个注入器注入的$rootScope服务不能用另一个注入器的$q服务创建的$apply/$digest来解析承诺吗

这可以通过使用typescript编写的以下测试进行复制:

describe("TestInjection", () => {

    let rootScope1 : angular.IRootScopeService;
    let q1 : angular.IQService;
    let rootScope2 : angular.IRootScopeService;
    let q2 : angular.IQService;

    beforeEach(() => {
        let $injector1 : angular.auto.IInjectorService = angular.injector(["ng"]);
        let $injector2 : angular.auto.IInjectorService = angular.injector(["ng"]);
        // noinspection TsLint

            q1 = $injector1.get("$q");
            q2 = $injector2.get("$q");
            rootScope1 = $injector1.get("$rootScope");
            rootScope2 = $injector2.get("$rootScope");
    });

    describe("with regard injection and promise testing", () => {

        it("promise should be resolved if both services come from the same injector", () => {
            let deferred = q1.defer();
            let value = false;
            deferred.promise.then((v : boolean) => {
                value = v;
            });
            deferred.resolve(true);
            rootScope1.$digest();
            expect(value).toBeTruthy();
        });

        it("promise should be resolved if both services come from different injectors", () => {
            let deferred = q1.defer();
            let value = false;
            deferred.promise.then((v : boolean) => {
                value = v;
            });
            deferred.resolve(true);
            rootScope2.$digest();
            expect(value).toBeTruthy();
        });
    });
});
我很想理解为什么事情会这样