NoctisHsu
2/3/2017 - 3:55 AM

AuthServiceImmediate.ts

namespace NineYi.Mall.Services {
    export class AuthServiceImmediate extends BaseServiceImmediate {
        public static $inject = ['$q', 'AuthService'];
        public IsLoginPromise: ng.IPromise<boolean>;

        constructor(public $q: ng.IQService,
                    private AuthService: NineYi.Mall.Services.AuthService) {
            super($q);
            this.IsLogin();
        }

        /**
         * 取得會員登入狀態
         * @constructor
         */
        private IsLogin(): void {
            var defer = this.$q.defer();
            super.CallHttpPromiseAction(this.AuthService.IsLogin()).then(
                (res: ng.IHttpPromiseCallbackArg<boolean>) => {
                    defer.resolve(res.data);
                });
            this.IsLoginPromise = defer.promise;
            this.IsLoginPromise.then((res: boolean) => {
                this.AuthService.LoginStatus = res;
            });
        }
    }

    angular.module('NineYi.Mall.Services')
        .service('AuthServiceImmediate', AuthServiceImmediate);
}