我如何等待this.Auth.ReLoad();做完才繼續往下做?
import { Component, OnInit, ViewChild } from ‘@angular/core’;
import { ShowAlert } from “…/service/ShowAlert.service”;
import { AuthReLoad } from “…/service/AuthReLoad.service”;
import { Default } from “…/model/Default.model”;
import { Cookie } from ‘ng2-cookies/ng2-cookies’;
import { RouterLink } from “…/service/RouterLink.service”;
import { DataBaseLink } from “…/service/DataBaseLink.service”;@Component({
selector: ‘app-news’,
templateUrl: ‘./news.component.html’,
styleUrls: [’./news.component.css’]
})export class NewsComponent implements OnInit {
constructor(private Connection: DataBaseLink, private Show_Alert: ShowAlert, private Auth: AuthReLoad, private Default_fun: Default, private Route: RouterLink) { }
Auth_News: string;
LV: string;
Factory_spinner = [];
news_kind = [];
main_body = [];
page_num = [];
page_num_val: number = 30
Order: string = “desc”;
pageNum: number = 0;
totalRows: number;
Current_page_num: number = 30;
Page_option: number = 30;
type: string = “”;
kind: string = “”;
subject: string;
before: string;
after: string;
release_to: string = “”;
first: string = “”;
isVisable: string = “”;ngOnInit() {
this.Route.Loading();
this.Auth.ReLoad();
localStorage.setItem(‘page_order’, this.Order);
localStorage.setItem(‘Current_page_num’, this.Page_option.toString());
this.Auth_News = sessionStorage.getItem(‘Auth_News’);
this.LV = Cookie.get(‘LV’);
this.Factory_spinner = this.Default_fun.news_type();
this.news_kind = this.Default_fun.news_kind();
this.page_num = this.Default_fun.Page();
this.Connection.Query_Post(“News_main/Index”, {
page_order: this.Order,
pageNum: this.pageNum,
Current_page_num: this.Page_option,
Auth_News: sessionStorage.getItem(‘Auth_News’)
}).subscribe(
data => {
this.main_body = data;
console.log(data);
if (data.length == this.Page_option) {
this.totalRows = Math.floor(data.length / this.Page_option) - 1;
}
else {
this.totalRows = Math.floor(data.length / this.Page_option);
}this.totalRows = Math.max(this.totalRows, this.pageNum); console.log(this.Auth_News); }, error => { this.Show_Alert.Show_error(); } ); this.Route.Loading_cancel();
}
Auth.ReLoad最後才做完