我在 Angular 7 中有一個布爾值,我用它在對象構造函數中設置一個值。布爾值作為參數傳遞,我將其存儲在本地。但是,由于某種原因,布爾值總是評估為真。這是有問題的代碼: ngOnInit() { this.id = this.route.snapshot.params['id']; this.showPersonal = this.route.snapshot.params['showPersonal']; console.log("ngOnInit, this.id: " + this.id); console.log("ngOnInit, this.showPersonal: " + this.showPersonal); // if showPersonal is true, workRelated i.e. last item in constructor, is false if (this.showPersonal){ console.log("showPersonal is true, setting work related to false") this.showWorkRelated = false; } else { console.log("showPersonal is false, setting work related to true") this.showWorkRelated = true; }console.log("this.showWorkRelated: " + this.showWorkRelated)這是輸出:todo.component.ts:28 ngOnInit, this.showPersonal: falsetodo.component.ts:32 showPersonal is true, setting work related to falsetodo.component.ts:40 this.showWorkRelated: false我嘗試了很多不同的方法,但它總是評估為真。這段代碼有什么問題?
Angular 7 - 布爾值始終為真
精慕HU
2021-08-26 16:23:57