在下面的代码中,我的国家/地区选择选项被多次触发以致浏览器停止响应。
<div [formGroup]="countryForm">
<mat-form-field>
<mat-select formControlName="selectedCountry" class="my-item-text" placeholder="Country">
<mat-option (onSelectionChange)="onCountrySelectionChanged($event)" *ngFor="let myCountry of countries" [value]="myCountry.short" class="my-item-text">{{ myCountry.name }}
</mat-option>
</mat-select>
</mat-form-field>
</div>
Run Code Online (Sandbox Code Playgroud)
和我的组件代码如下
onCountrySelectionChanged(changeEvent) {
if (changeEvent && changeEvent.isUserInput && this.selectedCountry != changeEvent.source.value) {
this.countrySelected.emit( changeEvent.source.value);
}
}
Run Code Online (Sandbox Code Playgroud)
我试图通过检查它的用户更改事件 [isUserInput] 并检查值是否真的改变来进行限制!现在可以减少火灾事件并且应用程序正常工作。
有没有更好的方法来使用选择选项,因为我现在在使用 mat-select 组件的任何地方都包括上述逻辑。
我多年来一直是后端开发人员,但我对前端非常陌生。在过去的几周里,我一直在为一个工作项目学习 Angular 6 和 Bootstrap 4。
我有一个基本的 Angular 6 应用程序设置,并且我成功地使用了 Bootstrap 4,默认主题/样式。为了得到我目前的位置,我做了以下事情:
ng new project-name --style=scss –routing,所以我有一个src/styles.scss文件@import "~bootstrap/scss/bootstrap"; // Bootstrap 4 and it's defaults
"styles": [
"src/styles.scss"
],
"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"
]
已决定使用Maisonnette 主题为应用程序提供更“企业化”的外观。我们已经购买了主题,我已经下载并扩展了 .zip 文件……现在我迷路了。我不知道:
感觉这应该非常简单,并且应该可以在 Google、YouTube 和/或 StackOverflow 上找到大量示例。但是,我没有找到任何运气。一切似乎都是关于用一些变量来调整默认主题;不是批发更换。
任何帮助将不胜感激。
谢谢。
我正在尝试将固定宽度的 MatDialog 水平居中:
let dialog = this.dialog.open(EditVisitPopupComponent,
{ data: { visit: this.visit }, width: '100%', maxWidth: '500px' });
Run Code Online (Sandbox Code Playgroud)
出于某种原因,添加width参数会justify-content: flex start向父叠加层添加内联,而我希望它保持不变justify-content: center。
我知道创建模态的方法,包括创建一个Overlay并将组件注入其中。但我不明白为什么我不能简单地使用MatDialog.
我试过的:
let dialog = this.dialog.open(EditVisitPopupComponent,
{ data: { visit: this.visit }, position: this.overlay.position().global().centerVertically().centerHorizontally(), width: '100%', maxWidth: '500px' });
Run Code Online (Sandbox Code Playgroud)
但类型不匹配。
我也试过backdropClass和一个兄弟 CSS 选择器,但我没有得到想要的结果。
我错过了什么?有没有办法配置Overlaya 的MatDialog?
如何在提交时在我的函数中制作包含“操作成功”的消息?
onSubmit() {
this.userService.createUser(this.addForm.value)
.subscribe( data => {
this.router.navigate(['list-user']);
});
}
Run Code Online (Sandbox Code Playgroud)
我更愿意用我的 html 内容附加我的空段落。
<div class="col-md-6">
<form [formGroup]="addForm" (ngSubmit)="onSubmit()">
<p class="msg_success"></p>
<button class="btn btn-success">Add user</button>
</form>
</div>
Run Code Online (Sandbox Code Playgroud) 我已经为我的mat-table. 但是,表格及其内容不遵守设置的高度。我想向这个表添加一个垂直滚动。

<div style="height: 200px;">
<mat-table>table content</mat-table>
</div>
Run Code Online (Sandbox Code Playgroud) 我从https://l-lin.github.io/angular-datatables/#/getting-started安装数据表角度指令
从https://l-lin.github.io/angular-datatables/#/extensions/buttons安装数据表按钮扩展
"styles": [
"src/styles.css",
"node_modules/bootstrap/dist/css/bootstrap.min.css",
"node_modules/datatables.net-dt/css/jquery.dataTables.css",
"node_modules/datatables.net-buttons-dt/css/buttons.dataTables.css"
],
"scripts": [
"node_modules/jquery/dist/jquery.js",
"node_modules/datatables.net/js/jquery.dataTables.js",
"node_modules/datatables.net-buttons/js/buttons.colVis.js",
"node_modules/datatables.net-buttons/js/buttons.flash.js",
"node_modules/datatables.net-buttons/js/buttons.html5.js",
"node_modules/datatables.net-buttons/js/buttons.print.js"
]
},
Run Code Online (Sandbox Code Playgroud)
"dependencies": {
"@angular/animations": "6.0.7",
"@angular/common": "6.0.7",
"@angular/compiler": "6.0.7",
"@angular/core": "6.0.7",
"@angular/forms": "6.0.7",
"@angular/http": "6.0.7",
"@angular/platform-browser": "6.0.7",
"@angular/platform-browser-dynamic": "6.0.7",
"@angular/platform-server": "6.0.7",
"@angular/router": "6.0.7",
"@nguniversal/module-map-ngfactory-loader": "^5.0.0-beta.5",
"angular-datatables": "^6.0.0",
"aspnet-prerendering": "^3.0.1",
"bootstrap": "^3.3.7",
"core-js": "^2.4.1",
"datatables.net": "^1.10.19",
"datatables.net-buttons": "^1.5.3",
"datatables.net-buttons-dt": "^1.5.3",
"datatables.net-dt": "^1.10.19",
"jquery": "^3.3.1",
"jszip": "^3.1.5",
"rxjs": "^6.2.1",
"zone.js": "^0.8.26"
},
Run Code Online (Sandbox Code Playgroud)
当我运行这个项目然后返回这样的错误:在此处输入图像描述
未捕获的类型错误:无法读取 button.flash.js 中未定义的属性“版本”
我试图在 [ngClass] 上使用多个类选择的条件:
<td>
<span
[ngClass]="{
'badge badge-success': {{ server.type }} === 'PRODUCTION',
'badge badge-danger': {{ server.type }} === 'TEST',
'badge badge-warning': {{ server.type }} === 'DEV'
}">
</span>
</td>
Run Code Online (Sandbox Code Playgroud)
我知道 [ngClass] 不适用于 {{ }} ,我从 restapi django app 获取我的数据,有什么替代方法可以做到这一点?谢谢
我有一个拍卖应用程序,我需要在其中显示每个用户的实时出价。我想使用的技术是前端的 Angular 6、实时通信的 Signal R 和后端 api 的 Asp.net MVC。我尝试使用@aspnet/signalR 以及 ng2-signalR
以下是我的一些代码:
App.component.ts
import { Component, Injectable } from '@angular/core';
import { SignalR, SignalRConnection, ISignalRConnection, BroadcastEventListener } from '../../node_modules/ng2-signalr';
import { Route, ActivatedRoute, Resolve } from '@angular/router';
import { BidService } from './app.service';
import { BidBlotter } from './Bid.Model';
import * as signalR from '@aspnet/signalr';
import { HubConnection } from '@aspnet/signalr';
// import '~/signalr/hubs';
declare var $: any;
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent …Run Code Online (Sandbox Code Playgroud) 我正在使用 angular 6 尝试使用 httpclient 发送 post 请求,但总是在服务器端收到空正文。
save( rules:RuleModel[]){
let _headers: HttpHeaders = new HttpHeaders({
'Content-Type': 'application/json; charset=utf-8'
});
return this._httpClient.post(AppConfig.BaseUrl,JSON.stringify(rules), {headers:_headers} ); }
Run Code Online (Sandbox Code Playgroud)
和 API 函数
[HttpPost]
public List<Rule> AddTemplateTextRules( [FromBody]Rule[] Rules)
{
try
{
return RuleManager.AddRule(Rules);
}
catch (Exception e)
{
return null;
}
return null;
}
Run Code Online (Sandbox Code Playgroud) 我正在为 angular 6 应用程序使用 NG_ZORRO 蚂蚁设计。我创建了一个组件来使用 nz-upload 上传图像。现在我想使用上传图像的自定义请求,该请求包含上传图像的操作和请求标头。
angular6 ×10
angular ×5
angular-cdk ×1
angular5 ×1
antd ×1
asp.net-core ×1
asp.net-mvc ×1
bootstrap-4 ×1
button ×1
c# ×1
datatable ×1
datatables ×1
rxjs6 ×1
signalr ×1
signalr-hub ×1
typescript ×1