我是打字稿的新手,我得到了这个错误
类型'Observable'不能分配给'IProduct []'.'Observable'类型中缺少属性'includes'.
我的服务类是:
getProducts() : Observable<IProduct[]> {
return this._http.get<IProduct[]>(this._productUrl)
.do(data=>console.log('All: ' + JSON.stringify(data)))
.catch(this.handleError);
}
private handleError(err : HttpErrorResponse){
console.log(err.message);
return Observable.throw(err.message)
}
Run Code Online (Sandbox Code Playgroud)
它在哪里错了,我应该怎么做才能解决它?
我有一个对象:
export class ReccurrenceModel {
fromDate: Date;
toDate: Date;
weeklyReccurrence: number;
state: State;
isMonday: boolean;
isTuesday: boolean;
isWednesday: boolean;
isThursday: boolean;
isFriday: boolean;
fromDateToReturn: Date;
toDateToReturn: Date;
}
Run Code Online (Sandbox Code Playgroud)
我像这样使用它
if (this.reccurrenceSelected === true) {
this.reccurrence.isMonday = this.mondaySelected;
this.reccurrence.isTuesday = this.tuesdaySelected;
this.reccurrence.isWednesday = this.wednesdaySelected;
this.reccurrence.isThursday = this.thursdaySelected;
this.reccurrence.isFriday = this.fridaySelected;
}
Run Code Online (Sandbox Code Playgroud)
我想为它们设置一个默认值 - false 因为如果我不在 UI 中设置它们,它们将是未定义的,我不想要那样。
如何在打字稿中设置布尔值的默认值?
我正在使用 bootstrap4 navs 和一个表单,我试图将 css 类更改为显示:none; 对于每个未选择的选项卡,我尝试使用 ngClass 来实现此目的,但没有起作用 stackblitz demo
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="itemSummary-tab" data-toggle="tab" href="#itemSummary" role="tab" aria-controls="itemSummary" aria-selected="true">Item Summary</a>
</li>
<li class="nav-item">
<a class="nav-link" id="details-tab" data-toggle="tab" href="#details" role="tab" aria-controls="details" aria-selected="false">Details</a>
</li>
<li class="nav-item">
<a class="nav-link" id="measurement-tab" data-toggle="tab" href="#measurement" role="tab" aria-controls="measurement" aria-selected="false">Measurement</a>
</li>
</ul>
<div class="tab-pane fade show active" ngClass="!active? display:none" id="itemSummary" role="tabpanel" aria-labelledby="itemSummary-tab">
....
</div>
<div class="tab-pane fade" id="measurement" ngClass="!active? display:none" role="tabpanel" aria-labelledby="measurement-tab">
...
</div>
<div class="tab-pane fade" id="details" role="tabpanel" aria-labelledby="details-tab"> …Run Code Online (Sandbox Code Playgroud) 我有一个带有复选框和按钮的 Angular 组件,如果未选中该复选框,则应禁用该按钮。什么是正确的方法?
<div class="form-check my-5">
<input type="checkbox" class="form-check-input id="agreements">
<label class="form-check-label" for="agreements">I have signed the agreements</label>
</div>
<button type="button" class="btn btn-outline-danger">Continue</button>
Run Code Online (Sandbox Code Playgroud) 我试图将一个日期对象推入一个数组,我得到这个错误"无法读取属性'推送'未定义".
export class CalendarComponent {
days: Date[]
showMonths() {
const interval = new Interval();
interval.fromMonth = this.selectedFromMonth.number;
interval.fromYear = this.selectedFromYear.number;
interval.toMonth = this.selectedToMonth.number;
interval.toYear = this.selectedToYear.number;
for (let i = interval.fromMonth - 1; i < 11; i++) {
const day = new Date(interval.fromYear, i, 1);
this.days.push(day);
// console.log(day);
// days.push(day);
}
// console.log(day);
}
Run Code Online (Sandbox Code Playgroud)
如果'days'已经是一个数组并且'day'没有未定义,为什么我会收到此错误?
如何将字符串var numbers = "2016, 2017, 2018";转换为List<int>?
我试过这个:
List<int> years = Int32.Parse(yearsString.Split(',')).ToList();
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误消息:
无法从string []转换为字符串.
angular ×6
html ×2
typescript ×2
arrays ×1
boolean ×1
c# ×1
capitalize ×1
css ×1
javascript ×1
string ×1