我有一个使用 Material Design 的 Angular6 应用程序。运行“ng test”时,出现以下错误:
失败:模板解析错误:无法绑定到“value”,因为它不是“mat-select”的已知属性。
我在导入和导出中包含了 MatSelectModule。它在应用程序中运行良好,但在测试期间失败。
material-design.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MatFormFieldModule, MatInputModule, MatSelectModule} from '@angular/material';
@NgModule({
imports: [MatFormFieldModule, MatInputModule, MatSelectModule],
exports: [MatFormFieldModule, MatInputModule, MatSelectModule],
})
export class MaterialDesignModule { }
Run Code Online (Sandbox Code Playgroud)
选择示例:
<mat-form-field class='select_buttons'>
<mat-select (selectionChange)='typeSelection_changed($event)' [(value)]='type'>
<mat-option *ngFor="let type of types" [value]="type"> {{type.name}}</mat-option>
</mat-select>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud) 我正在使用Angular Material Select显示假期。当用户选择假期时,我想显示日期而不是假期名称。例如,如果用户选择“圣诞节”,则我希望所选值显示为“ 12月25日”
<mat-form-field>
<mat-select [(ngModel)]="selectedHoliday" placeholder="Select A Holiday" (change)="eventSelection($event.value)">
<mat-option *ngFor="let holiday of holidays" [value]="holiday">{{ holiday.name }}</mat-option>
</mat-select>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)
我在选择更改时将ngmodel设置为正确的日期:
selectedHoliday: string;
holidays = [
{ name: 'Christmas', date: 'Dec 25'} ,
{ name: 'New Years', date: 'Jan 1'}
]
eventSelection(event){
this.selectedHoliday = event.date
}
Run Code Online (Sandbox Code Playgroud)
当我将selectedHoliday设置为日期时,没有任何内容显示为所选值。这是一个小矮人:https ://plnkr.co/edit/9lhHJhNyuWUxqYF6nMwK ? p = preview
我必须在java中输出Julian日历.我每个月都打印出来,但是我不确定如何确定每个月对应的行长度.例如,2月,4月,6月,9月和11月没有31天.到目前为止这是我的代码:
import java.text.DateFormatSymbols;
public class testing {
public void Day() {
System.out.println();
for (int i = 1; i <= 31; i++) {
System.out.println(String.format("%2s", i));
}
}
public void MonthNames() {
String[] months = new DateFormatSymbols().getShortMonths();
for (int i = 0; i < months.length; i++) {
String month = months[i];
System.out.printf(month + " ");
//System.out.printf("\t");
}
}
public void ColRow() {
int dayNum365 = 1;
int array [][] = new int[31][12];
System.out.println();
for (int col = 0; col < 12; col++) …Run Code Online (Sandbox Code Playgroud) 我正在尝试将 JSON 对象附加到文本文件中的现有 JSON 对象。我的第一组数据如下所示。
data = [
{
"username": "Mike",
"code": "12345",
"city": "NYC"
}
]
Run Code Online (Sandbox Code Playgroud)
然后我需要将另一组 JSON 对象附加到现有文件中,如下所示:
data = [
{
"username": "Mike",
"code": "12345",
"city": "NYC"
},
{
"username": "Kelly",
"code": "56789",
"city": "NYC"
}
]
Run Code Online (Sandbox Code Playgroud)
当我尝试运行时:
with open('data2.txt', 'a') as outfile:
json.dump(data, outfile)
Run Code Online (Sandbox Code Playgroud)
我的数据的 JSON 格式不正确。您能建议如何正确附加到文本文件吗?