angular - 变量值在特定情况下没有更新角度?
问题描述
我dropdown
在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
在我的函数中更改变量的值component.ts
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;
})
}
问题是,当我单击模板跨度中更新的类别名称dropdown
以外的任何类别名称时。但是,当我单击时,然后当我更改为任何其他类别名称时,它不会在模板中更新值。All Categories
<span>{{selectedCategory}}</span>
All Categories
dropdown
<span>{{selectedCategory}}</span>
请在此处参考错误视频
解决方案
推荐阅读
- spring-data-jpa - java.lang.IllegalArgumentException:无法解析值“${crossOrigin}”中的占位符“crossOrigin”
- android - 无法让 Epson EPOS 打印机监听器工作以监控打印机的状态
- python - PyDictionary 无法连接到 wordnet 网站
- sql - Apache Ignite - 在 SQL Select 的情况下,Apache Ignite 返回结果是否有任何顺序?
- r - 如何根据列名对包含 R 中多个列表的列表进行子集化,并合并到单个列表/数据框中?
- sql-server - SQL Server 是否计算后来丢弃的结果?
- android - Kotlin Companion Objection 未解决的引用
- python - Spark Mongo 连接器:在 MongoDB 连接中只插入一个属性
- java - 停止在 Android APK 中生成 javax.annotation 源文件
- vba - 使用 .Replace 撤消 ID