Angular 变量值在特定场景下不更新?
我在Angular 变量值在特定场景下不更新?,angular,typescript,Angular,Typescript,我在angular应用程序中有一个自定义的下拉列表,其html如下所示 <div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab"> <div class="wrap-drop" id="noble-gases"> <span>{{selectedCategory}}</span> <ul class="drop"&
angular
应用程序中有一个自定义的下拉列表,其html如下所示
<div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">
<div class="wrap-drop" id="noble-gases">
<span>{{selectedCategory}}</span>
<ul class="drop">
<li (click)="getReferralsOnSelectChanged()"><a>All Categories</a></li>
<li *ngFor="let category of categories" (click)="categorySelectionChanged(category)"><a>{{category.name}}</a></li>
</ul>
</div>
selectedCategory: string = 'All categories';
getReferralsOnSelectChanged = () => {
console.log('in all categories')
this.selectedCategory = 'All categories';
this.getReferrals();
}
categorySelectionChanged = (cat) => {
console.log('change : ', cat)
this.selectedCategory = cat.name;
console.log('selected category : ',this.selectedCategory)
if (cat._id) {
this._dataService.get(`${this._const.companySearch}/${cat._id}`).subscribe(res => {
console.log('category search response : ', res);
if (res.success) {
this.referralLinkArr = res.data ? res.data : [];
this.masterReferralLinkArr = res.data ? res.data : [];
}
}, error => {
console.log('Search Category By referral Error : ', error);
})
} else {
this.getReferrals();
}
}
getReferrals = () => {
this.showLoader = true;
this._dataService.get(`${this._const.companyReferrals}`).subscribe(res => {
if (res.success) {
this.masterReferralLinkArr = res.data;
this.referralLinkArr = res.data;
}
this.showLoader = false;
}, error => {
console.log('get Referral Error : ', error)
this.showLoader = false;
})
}
问题是,当我在下拉列表中单击除所有类别
以外的任何类别名称时,类别名称会在{{selectedCategory}}
的模板span中更新。但当我点击下拉列表中的所有类别
时,以及之后当我更改为任何其他类别名称时,它不会更新模板{{selectedCategory}}
中的值
请参阅错误视频您能分享getReferrals()
的代码吗?控制台中有错误吗?@AlexK控制台中没有错误,我包括了有问题的getReferrals()
code post您是否可以尝试在StackBlitz中重现该问题@亚历克斯:不,很好。您是否更改了代码中的任何内容?能否共享getReferrals()
的代码?控制台中有错误吗?@AlexK控制台中没有错误,我包括了有问题的getReferrals()
code post您是否可以尝试在StackBlitz中重现该问题@亚历克斯:不,很好。你的代码中有什么改动吗?