我正在尝试在 Angular 12 中添加 Bootstrap 5 下拉列表,但它不起作用。
我已经安装了所有必需的软件包,并将它们添加到angular.json文件中。
从 Bootstrap 5 文档复制了确切的示例,但仍然不起作用。
在angular.json我已经给出
"styles": [
"node_modules/bootstrap/dist/css/bootstrap.min.css"
],
"scripts": [
"node_modules/jquery/dist/jquery.min.js",
"node_modules/popper.js/dist/umd/popper.min.js",
"node_modules/bootstrap/dist/js/bootstrap.min.js"
]
Run Code Online (Sandbox Code Playgroud)
下面是我的 HTML 代码(与 Bootstrap 5 文档中的相同)
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton1" data-
bs-toggle="dropdown" aria-expanded="false">
Dropdown button
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
我使用命令npm i来安装软件包,但没有提及任何版本名称,所以我猜安装了最新版本。安装 jQuery 作为最后的手段读到 Bootstrap 5 不需要 jQuery。任何帮助是极大的赞赏。
home.component.ts
global: boolean = false;
country!: string;
data: GlobalData;
dailyData: any[] = [];
countries: any[] = [];
lineChartData: any[] = [
{
data: [65, 64, 33, 44],
label: 'Temp label'
}
];
lineChartType = "line";
lineChartLabels: any[] = [
'label01', 'label02', 'label03'
];
barChartData: any[] = [
{
data: [65, 76, 33],
label: 'Label'
}
];
Run Code Online (Sandbox Code Playgroud)
home.component.html
<canvas baseChart
[chartType] = "lineChartType"
[datasets] = "lineChartData"
[labels] = "lineChartLabels"
>
</canvas>
Run Code Online (Sandbox Code Playgroud)
错误:
类型“string”不可分配给类型“keyof ChartTypeRegistry”
错误行:
[chartType] = "lineChartType"
Run Code Online (Sandbox Code Playgroud)
错误发生在 home.component.html
我需要一个解决方案。尝试在谷歌上找到解决方案,但我找不到。
我需要使用 MongoDB 中的运算符执行分组$max。我找出了在 MongoDB 数据库中运行的查询,但无法使用 C# 编写相同的查询。
db.getCollection('Employee').aggregate(
[
{$unwind : "$Projects"},
{
"$group" : {
"_id" : "$EmpId",
"LastUpdated" : {"$max" : "$Projects.LastUpdated"}
}
}
]);
Run Code Online (Sandbox Code Playgroud)
下面的 C# 代码出现错误:
“项目”不是有效的财产。
db.getCollection('Employee').aggregate(
[
{$unwind : "$Projects"},
{
"$group" : {
"_id" : "$EmpId",
"LastUpdated" : {"$max" : "$Projects.LastUpdated"}
}
}
]);
Run Code Online (Sandbox Code Playgroud) 如标题所述,NG-ZORRO 的部分图标无法渲染。
预计会渲染 5 个图标,但实际只渲染了 2 个。
查看附加的输出
main.component.html
<nz-layout class="full-screen">
<nz-sider nzCollapsible
[(nzCollapsed)]="isCollapsed"
[nzWidth]="260">
<app-left-control></app-left-control>
</nz-sider>
<nz-content class="container">
<i nz-icon nzType="step-backward" nzTheme="outline"></i> Cannot render<br>
<i nz-icon nzType="down" nzTheme="outline"></i> Can render<br>
<i nz-icon nzType="caret-left" nzTheme="outline"></i> Cannot render<br>
<i nz-icon nzType="double-right" nzTheme="outline"></i> Can render<br>
<i nz-icon nzType="setting" nzTheme="outline"></i> Cannot render<br>
</nz-content>
</nz-layout>
Run Code Online (Sandbox Code Playgroud)
主模块.ts
<nz-layout class="full-screen">
<nz-sider nzCollapsible
[(nzCollapsed)]="isCollapsed"
[nzWidth]="260">
<app-left-control></app-left-control>
</nz-sider>
<nz-content class="container">
<i nz-icon nzType="step-backward" nzTheme="outline"></i> Cannot render<br>
<i nz-icon nzType="down" nzTheme="outline"></i> Can render<br>
<i nz-icon nzType="caret-left" nzTheme="outline"></i> Cannot render<br> …Run Code Online (Sandbox Code Playgroud) 我是角度新手。我一直在尝试对列进行排序,但不断收到此错误:
“Event”类型的参数不可分配给“SortEvent”类型的参数。类型“Event”缺少类型“SortEvent”中的以下属性:列、方向 - ngtsc(2345)。
关于如何开展这项工作有什么建议吗?
s-产品管理.component.html:
<form>
<div class="form-group form-inline">
Full text search: <input class="form-control ml-2" type="text" name="searchTerm" [(ngModel)]="service.searchTerm"/>
<span class="ml-3" *ngIf="service.loading$ | async">Loading...</span>
</div>
<table class="table table-striped">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col" sortable="name" (sort)="onSort($event)">Country</th>
<th scope="col" sortable="area" (sort)="onSort($event)">Area</th>
<th scope="col" sortable="population" (sort)="onSort($event)">Population</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let product of products$ | async">
<th scope="row">{{ product.id }}</th>
<td>
<img [src]="'https://upload.wikimedia.org/wikipedia/commons/' + product.flag" class="mr-2" style="width: 20px">
<ngb-highlight [result]="product.name" [term]="service.searchTerm"></ngb-highlight>
</td>
<td><ngb-highlight [result]="product.area | number" [term]="service.searchTerm"></ngb-highlight>
</td>
<td><ngb-highlight [result]="product.population | number" …Run Code Online (Sandbox Code Playgroud) 在这里,我在自动完成下拉列表中获得了国家/地区列表,并尝试通过国家/地区名称的开头字母来过滤这些国家/地区。
示例:如果我们输入“Aus”,则所有带有“aus”的国家/地区名称都会被过滤。(参见屏幕截图)。我只想过滤“澳大利亚和奥地利”或以“Aus”开头的任何其他国家/地区名称。
怎么做?
<ng-autocomplete #countryList formControlName="locationCountry" [data]="countries"
min-length="1" [searchKeyword]="countrykeyword"
[initialValue]="countrykeyword"
(selected)='selectEventCountry($event);onLocationSubmit();'
(inputCleared)='onCountryCleared($event, false)'
[itemTemplate]="countryListTemplate"
[notFoundTemplate]="notFoundTemplate" placeHolder="Enter Country">
</ng-autocomplete>
Run Code Online (Sandbox Code Playgroud) 我在 FormArray 方面遇到问题,可能需要一些帮助。\n我有一个带有变量 FormArray 的表单,它可以工作,我可以将数据发送到后端。\n问题是,我无法设置从我收到的数据中的值后端。
\n这是打字稿代码:
\nthis.form = this.fb.group({\n title: new FormControl("",[Validators.required]),\n actors: new FormArray([])\n})\n\nthis.moviesService.getMovie(this.movieId).subscribe(movieData => {\n this.movie = movieData;\n this.form.patchValue({\n title: this.movie.title,\n actors: this.movie.actors, \n })\n})\nRun Code Online (Sandbox Code Playgroud)\n然后在 html 中单击按钮,我调用此函数:
\naddActor(){\n const actorsForm = this.fb.group({\n actor: \'\',\n role: \'\'\n })\n this.actors.push(actorsForm);\n}\n\nremoveActor(i: number){\n this.actors.removeAt(i);\n}\nRun Code Online (Sandbox Code Playgroud)\n和 HTML:
\n<form [formGroup]="form" (submit)="onSubmit()">\n <table formArrayName="actors">\n <tr>\n <th colspan="2">Besetzung:</th>\n <th width="150px">\n <button type="button" mat-stroked-button color="primary" (click)="addActor()">Hinzuf\xc3\xbcgen +</button>\n </th>\n </tr>\n <tr *ngFor="let actor of form.get(\'actors\')[\'controls\']; let i=index" [formGroupName]="i">\n <td>\n …Run Code Online (Sandbox Code Playgroud) 我想在一个标签中设置两个值。例如,如果我打开下拉菜单,它应该显示为:
“值1 值2”
与空间在一条线上。value1数据value2是从数据库中获取的。我尝试使用下面的方法,但没有成功。
<p-dropdown [options]="divitionArr" name="business_divition" [(ngModel)]="project.business_divition" optionLabel="{'first_name','last_name'}" optionValue="divition" #diviSel="ngModel"></p-dropdown>
Run Code Online (Sandbox Code Playgroud) angular ×7
typescript ×4
c# ×2
html ×2
mongodb ×2
angular12 ×1
antd ×1
asp.net-core ×1
autocomplete ×1
bootstrap-5 ×1
chart.js ×1
filter ×1
formarray ×1
httpcookie ×1
javascript ×1
mongoose ×1
ng-bootstrap ×1
ng2-charts ×1
primeng ×1