我想在頁面啓動時打開一個新的頁面,但我不斷收到一個角4 NgOnInitReference錯誤
Reference Error: Window not defined.
我只開始與打字稿及Angular4最近的工作,所以我不這樣確定這個問題真正屬於哪一個。
export class HomeComponent implements OnInit {
testCall: Window;
constructor() {
this.testCall = new Window();
this.testCall.open(
"https://static.pexels.com/photos/104827/cat-pet-animal-domestic-104827.jpeg");
}
ngOnInit(): void {
console.log("function read");
window.open("https://static.pexels.com/photos/104827/cat-pet-animal-domestic-104827.jpeg");
}
即使我使用this.testCall.open
的OnInit()
裏面,我只得到一個參考錯誤,但在open
方法。
我知道這是一個簡單的頁面打開時,第一頁打開,但它已經一個星期了,我真的不知道如何在打字稿/ angular4設置中做到這一點。
已經嘗試過,沒有工作。窗口未定義。 :( – RoboKy
你需要刪除該行,如果郵件仍然存在,那麼你並沒有刪除它 – trichetriche
當然,我刪除了該行,除了現在它給我「TypeError:無法讀取未定義的屬性」打開「真的很抱歉對於這個問題 – RoboKy