我是Angular2的新手.现在我需要限制输入字段中的特殊字符,如果我给它必须采用的数字和字母,应该阻止特殊字符.可以任何人帮助请.
我在这里分享代码:
In HTML:
<md-input-container>
<input type="text" (ngModelChange)="omit_special_char($event)" mdInput name="name" [(ngModel)]="company.name" placeholder="Company Name" #name="ngModel" minlength="3" required>
</md-input-container>
Run Code Online (Sandbox Code Playgroud)
在TS:public e:any;
omit_special_char(val)
{
var k;
document.all ? k = this.e.keyCode : k = this.e.which;
return ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 8 || k == 32 || (k >= 48 && k <= 57));
}
Run Code Online (Sandbox Code Playgroud) 我有 3 个带有标记的地方,我需要为所有 3 个标记提供不同的颜色,任何人都可以帮助我。我也尝试过在对象内部提供颜色,但没有任何效果。我需要为给定的所有 3 个坐标点提供 3 种随机颜色。我还想在数组中循环该组件,并且应该使用 *ngFor 调用 html bu。
成分:
import mapboxgl from 'mapbox-gl';
mapboxgl.accessToken = 'pk.eyJ1IjoicmFrc2hpdGhhMTkiLCJhIjoiY2pjcHl1YW5wMjR5czJ6bzdqdjZrbDRzeSJ9.OOqu6zVyNsXavzCsYoBdPA';
var map = new mapboxgl.Map({
container: 'maps',
style: 'mapbox://styles/mapbox/streets-v9',
center: [12.568337,55.676098],
zoom: 9
});
map.on('load', function () {
map.addLayer({
"id": "points",
"type": "circle",
"paint":{
"circle-radius":10,
"circle-color":
'green'
},
"source": {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [
12.568337,55.676098
]
}
}
}
]
}
},
});
}); …Run Code Online (Sandbox Code Playgroud) 我有一个页面,它只有一个用户的东西。但是现在我必须创建一个表并且我需要获取数据,所以在表中我必须有内联的编辑和删除按钮。如果我点击编辑按钮,那么我必须能够编辑整行,删除意味着必须删除整行。当我单击“新建”按钮时,它必须为我创建一个包含编辑和删除操作的新行。我需要使用 ng-prime 本身来执行此操作。所以,任何人都可以帮助我提供链接或任何演示。
当我运行应用程序时,我面临错误
无法绑定到“globalFilter”,因为它不是“p-table”的已知属性。1.如果'p-table'是一个Angular组件并且它有'globalFilter'输入,那么验证它是这个模块的一部分。
HTML:
<p-table [columns]="tableHeaders" [value]="listEmrAllergy" [paginator]="true" [rows]="10" (onLazyLoad)="loadLazy($event)" [totalRecords]="totalcount" [lazy]="!press" [globalFilter]="dt">
Run Code Online (Sandbox Code Playgroud)
TS:
import { TableModule } from 'primeng/table';
Run Code Online (Sandbox Code Playgroud) 我已经使用carousel过,我曾经用来activeSlideIndex获取该特定图像的编号。所以我在控制台中收到一个错误
Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'undefined'. Current value: '0'.
Run Code Online (Sandbox Code Playgroud)
HTML部分:
<carousel class="carousel slide"[(activeSlide)]="page.activeSlideIndex">
<slide *ngFor="let image of images; let i = index ">
<p>Image {{i+1}}</p>
<img src="{{image.image}}" >
<p >
<input type="file" name="file" id="file" (change)="readUrl($event)" />
<label (click)="changed(page.activeSlideIndex)">Change</label>
</p>
</slide>
</carousel>
Run Code Online (Sandbox Code Playgroud)
ts:
images:any = [{image :'img1.jpg', change:'change'},{image: 'img2.jpg', change:'add'},{image:'img3.jpg', change:'edit'},{image:'im4.jpg',change:'delete' }];
changed(index){
console.log(index);
}
Run Code Online (Sandbox Code Playgroud) 我的 HTML 中有一个 ng-select 字段,我想将 css 的某些部分应用到该字段,这里我使用的是 scss,我不知道如何将这些代码与我给出的类交叉,谁能帮我排序出来。
Scss:
.box {
background-color: #4389a9;
width: 185px;
height: 45px;
padding: 8px 20px;
right: -19px;
cursor: pointer;
top: 19px;
transition: bottom 2s;
border-radius: 24px;
margin-bottom: 26px;
select-dropdown {
display: none;
}
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<ng-select class="box" placeholder="Wiredelta" [options]="cities">Wiredelta</ng-select>
Run Code Online (Sandbox Code Playgroud)
要添加到 scss 的 CSS 部分:
ng-select > div > div.single > div.toggle {
color: white !important;
background: none;
}
ng-select > div {
border:none !important
}
ng-select > div > div.single > div.placeholder {
color: white; …Run Code Online (Sandbox Code Playgroud) 我有一个消息对话部分,在那里我需要将滚动条显示到底部,当页面再次打开时,滚动条必须在底部。我的意思是应该首先显示最后一条消息。
HTML:
<ul>
<li *ngFor="let reply of message_show.messages">
<img [src]="reply.from_user_image || '../assets/images/msg.png'"/>
<p><b>{{reply.name}} </b> <span> {{reply.updated_at | date:'dd.MM.yyyy'}} - {{reply.updated_at | date:'h:mm'}}</span></p>
<p>{{reply.text}}</p>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
:
loadMessages() {
this.service
.getMessages()
.subscribe(
data => {
this.messagesdata = data;
this.activeMessages = data.filter(msg => msg.active == true && msg.from_user_name !== 'Anonymus' && msg.messages.length > 0)
this.closedMessages = data.filter(msg => msg.active == false && msg.from_user_name !== 'Anonymus' && msg.messages.length > 0);
if (this.activeMessages.length > 0) {
if(!this.message_show) {
var test = this.message_show = this.activeMessages[0]; …Run Code Online (Sandbox Code Playgroud) 您好,我从 API 命中获取对象数组,该对象数组必须分配给 formGroup。我尝试过使用 formGroup 绑定,但它检测到真/假值,但它不会给我对象数组中更改的真/假值,而是只给我真/假,而且我在另一个数组中也有日期输入字段,它也不会检测真/假值或更改的值。如果我写的代码是错误的,那么请纠正我并帮助我以有效的方式编写。
帮助表示赞赏。
演示:演示
TS:
private settingsInfoForm() {
if (!this.agentDetailsList) {
// Add
this.agentSettingsInfoForm = this.FB.group({
agentToogles: this.FB.array(this.detailsToggle.map(x=> x.boolValue)),
restrictionsInfo:this.FB.array(this.Restrictions.map(x=>x.boolValue))
});
} else {
// Edit
if (this.agentDetailsList) {
this.detailsToggle = this.agentDetailsList
this.agentSettingsInfoForm = this.FB.group({
agentToogles: this.FB.array(this.detailsToggle.map(x=>x.boolValue)),
restrictionsInfo:this.FB.array(this.Restrictions.map(x=>x.boolValue))
})
}
this.agentSettingsInfoForm.valueChanges.subscribe(data => {
this.formEdit = true;
console.log('agentSettingsInfoForm', this.formEdit)
})
}
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<form [formGroup]= "agentSettingsInfoForm">
<div class="row row-cols-2" formGroupName="agentToogles">
<div class="col" *ngFor="let toggleValue of detailsToggle;let i = index">
<div class="custom-control custom-switch mb-3">
<input type="checkbox" [formControlName]="i" …Run Code Online (Sandbox Code Playgroud) 我有2个字段,密码和确认密码。那么,我该如何验证两者呢?HTML:
<div class="mb-4 col-lg-6">
<label >Password
<span class="required">*</span>
</label>
<input class="form-control" type="password" placeholder="Password"
formControlName="Password">
<control-messages [control]="controls.Password" class="errorMessage"></control-messages>
<div class="errorMessage" *ngIf="validationPassBlank==1">{{errorMessage}}</div>
<div class='required' *ngIf="validationError == 1">{{errorMessage}}</div>
</div>
Run Code Online (Sandbox Code Playgroud) 我正在使用 primeng 的 p-fileUpload 插件,上传文件后,我仍然可以在成功消息后看到我上传的文件。任何人都可以帮助我如何在成功消息后隐藏这些文件。
HTML:
<p-fileUpload #form name="photo" type="file" customUpload="true" (uploadHandler)="fileChangeEvent($event, form)" multiple="multiple"></p-fileUpload>
Run Code Online (Sandbox Code Playgroud)
TS:
fileChangeEvent(fileInput: any, form) {
if (
fileInput.files.some(f => this._validFileExtensions.indexOf(f.type) != -1)
) {
this.showError("Invalid file Added");
} else {
this.upload(fileInput.files, form);
}
}
Run Code Online (Sandbox Code Playgroud)
调用此功能时我需要清除文件,
if (this.progressStatus === 'done') {
this.progressValue = 100;
this.progress = false;
clearInterval(interval);
return ;
}
Run Code Online (Sandbox Code Playgroud) 我有一个图像源,但如果来自后端的图像为空,那么我必须显示默认图像,或者必须显示后端中的图像。谁能帮我做到这一点。如果图像部分为空,那么我必须显示该图像
"../assets/images/msg.png"
Run Code Online (Sandbox Code Playgroud)
HTML:
<ul>
<li *ngFor="let message of activeMessages" (click)="showMessage(message)" [class.activeShow]="message.id == message_id">
<span>{{message.updated_at | date:'dd.MM.yyyy'}}</span>
<img src="{{message.from_user_image}}" alt="img"/>
</li>
</ul>
<ul>
<li *ngFor="let reply of message_show.messages">
<img src="{{reply.from_user_image}}"/>
<p><b>{{reply.name}} </b> <span> {{reply.updated_at | date:'dd.MM.yyyy'}} - {{reply.updated_at | date:'h:mm'}}</span></p>
<p>{{reply.text}}</p>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
时间:
loadMessages() {
this.service
.getMessages()
.subscribe(
data => {
this.messagesdata = data;
this.activeMessages = data.filter(msg => msg.active == true);
this.closedMessages = data.filter(msg => msg.active == false);
if (this.activeMessages.length > 0) {
if(!this.message_show) {
var test = this.message_show …Run Code Online (Sandbox Code Playgroud) 我有一张表,我需要从打字稿中将这些详细信息填入我的表中。
1.Device Name
2. Device OS
3. Location
4. Browser
5. IsActive
Run Code Online (Sandbox Code Playgroud)
这些字段必须从打字稿中填写,所以任何人都可以帮我解决这个问题
angular ×11
typescript ×5
html ×2
carousel ×1
css ×1
formarray ×1
javascript ×1
mapbox-gl-js ×1
navigator ×1
primeng ×1
windows ×1