使用rxjs后升级到angular6少数问题
import {
Observable,
Subject,
asapScheduler,
pipe,
of,
from,
interval,
merge,
fromEvent
} from "rxjs";
import { delay } from "rxjs/operators";
let obser = from([ 1, 2, 3 ]).delay( 3000 );
Run Code Online (Sandbox Code Playgroud)
"可观察"类型上不存在"延迟"属性
在角度5这工作正常
import { Observable } from 'rxjs/Observable';
let obser = Observable.from([ 1, 2, 3 ]).delay(3000);
Run Code Online (Sandbox Code Playgroud) 我正在编写应用程序的前端代码,但在我的 Angular 6 注册代码中遇到了问题。我显然犯了一个 TypeError,但我不明白为什么它会是未定义的。
这是我的 registration.component.ts。
import { Component, OnInit } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule} from '@angular/platform-browser/animations';
import { NgModule } from '@angular/core';
import {RouterModule} from '@angular/router';
import {Routes} from '@angular/router';
import {
MatToolbarModule, MatButtonModule, MatInputModule, MatIconModule, MatSelectModule, MatTableModule, MatGridListModule,
MatCardModule, MatMenuModule, MatFormFieldModule, MatOptionModule, MatRadioModule
} from '@angular/material';
import {HttpClientModule } from '@angular/common/http';
import {FormBuilder, FormControl, FormsModule} from '@angular/forms';
import {FormGroup} from '@angular/forms';
import {Validators} from '@angular/forms';
import {ReactiveFormsModule} from '@angular/forms';
import …Run Code Online (Sandbox Code Playgroud) 我有两个组件:CustomerComponent和CustomerCreateUpdateComponent。
CustomerComponent包括客户数据表。
CustomerCreateUpdateComponent是一个带有用于创建/更新的输入控件的表单。
我mat-dialog用CustomerCreateUpdateComponent它。打开对话框并填写表格后,我单击提交按钮并this.dialogRef.close(customer);执行。customer对象具有所有值。
在CustomerComponent我已经subscribe上this.dialog.open(CustomerCreateUpdateComponent).beforeClose().subscribe((customer: Customer) => { ... });
这是beforeClose()方法,所以在对话框关闭之前,我取回customer对象并将其发布到 api。
如果 POST 成功,一切正常,对话框关闭并更新数据表。
但是,如果 POST 没有成功,api 将返回一个错误,我想向用户显示并保持对话框打开,类似于if(error) { closeEvent.cancel() }
我看过整个文档mat-dialog,没有任何帮助。我几乎可以肯定没有办法做到这一点。
也许有人有同样的问题?很高兴听到任何解决方法。
在angularJS中,您可以使用$ compile在iframe中呈现视图,并将angularjs $ scope变量保留在iframe中.Angular.IO中是否有相同的功能?
AngularJS在指令中等效:
var $body = angular.element($element[0].contentDocument.body);
var template = $compile(contents)($scope);
$body.append(template);
Run Code Online (Sandbox Code Playgroud)
我想渲染一个iframe,传递必要的html来填充iframe,并能够在iframe html中使用模板语言.
与此相似但是,这个plunkr不起作用.它不会在iframe视图中呈现变量.
更新:找到一些关于如何在打字稿中使用angularJS的教程,这可能有用.最后,我想在父和iframe之间共享变量,类似于在parent和iframe之间共享angularJS中的$ scope.
我尝试创建一个UI,其中有一个带有几个文本字段的表单,a input type="file"和a div可以删除要与表单其余部分一起上传的图像.
我的目标/逻辑
使用相同的方法div来删除图像或单击它并打开文件夹资源管理器,如input type="file"行为.在小屏幕中启用点击是有意义的,实际上不可能"拖放".并且由于input type="file"表格中已经有一个没有理由从中获取图像div并将其附加到表格等等.我尝试拍摄掉的图像div,将其设置为值input type="file"并提交形成一次.(如果用户点击了div,那么input type="file"已经有了一个值,所以我可以再次自由提交表单).
这是代码
<div id="imageDrop" (click)='imageInput.click()' (drop)="drop($event)" (dragover)="allowDrop($event)" #imageDrop>
</div>
<input type="file" formControlName="imageInput" required #imageInput id="imageInput" (change)='imageChange($event)' > <!-- use css to hide it -->
Run Code Online (Sandbox Code Playgroud)
所以,当imageDrop点击时,实际上调用imageChangevia(click)='imageInput.click()'
这是组件中的打字稿.
//imageUpload is the name of the reactive form
acceptedImageTypes = {'image/png': true,'image/jpeg': true,'image/gif': true};
@ViewChild('imageDrop') imageDrop;
allowDrop(e) {
e.preventDefault();
}
drop(e) …Run Code Online (Sandbox Code Playgroud) file-upload image-uploading angular angular-reactive-forms angular6
我有这个JPA查询,我想从Spring生成Angular Barchart:
public List<PaymentTransactionsDailyFacts> findPaymentTransactionsDailyFacts(LocalDateTime start_date, LocalDateTime end_date) {
String hql = "SELECT SUM(amount) AS sum_volume, COUNT(*) AS sum_Transactions " +
" WHERE (created_at BETWEEN :start_date AND :end_date )" +
" GROUP BY DATE(created_at)";
TypedQuery<PaymentTransactionsDailyFacts> query = entityManager.createQuery(hql,
PaymentTransactionsDailyFacts.class).setParameter("start_date", start_date).setParameter("end_date", end_date);
List<PaymentTransactionsDailyFacts> data = query.getResultList();
return data;
}
Run Code Online (Sandbox Code Playgroud)
预期的查询结果:
Date | Amount| Number of transactions per day |
11-11-2018 | 30 | 3 |
11-12-2018 | 230 | 13 |
Run Code Online (Sandbox Code Playgroud)
JPA查询中的映射对象:
public class DashboardDTO {
private Date date;
private int …Run Code Online (Sandbox Code Playgroud) 我已经定义了这样的路线:
const routes: Routes = [
{ path: '', loadChildren: './tabs/tabs.module#TabsPageModule' },
{ path: 'faq', loadChildren: './faq/faq.module#FaqPageModule' },
{ path: 'terms', loadChildren: './terms/terms.module#TermsPageModule' }
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule {}
Run Code Online (Sandbox Code Playgroud)
像这样:
const routes: Routes = [
{
path: 'tabs',
component: TabsPage,
children: [
{
path: '',
redirectTo: '/tabs/(list:list)',
pathMatch: 'full',
},
{
path: 'list',
outlet: 'list',
component: ListPage
},
{
path: 'profile',
outlet: 'profile',
component: ProfilePage,
canActivate: [AuthGuardService]
}
]
},
{
path: '',
redirectTo: …Run Code Online (Sandbox Code Playgroud) 我有一个数组作为集合,我想将其加载到下拉列表中,并希望在某种情况下进行默认选择,但我不知道该如何实现。
app.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-commingsoon',
templateUrl: './commingsoon.component.html',
styleUrls: ['./commingsoon.component.css']
})
export class CommingsoonComponent implements OnInit {
public collection = [];
constructor() {
for(let i = 1; i<=10 ; i++) {
this.collection.push(`Angular: ${i}`);
}
}
ngOnInit() {
}
}
Run Code Online (Sandbox Code Playgroud)
app.component.html
<select name="" id="" style="position:relative; left: 100px">
<option *ngFor="let i of collection;" value="{{i}}" [selected]="i == Angular: 2">{{ i }}</option>
</select>
Run Code Online (Sandbox Code Playgroud)
我希望下拉列表应为i == Angular:2时的选定值
在客户端(使用Angular 6),我需要使用HttpClient向服务器端发送Post请求。示例源代码如下
let request = {'username': 'username', 'password': 'password'}
this.httpClient.post("http://10.116.43.18:8002/user/login", request, { headers: new HttpHeaders().set('Access-Control-Allow-Origin','*'), observe: 'response' }).subscribe(
data => {
console.log("Success");
console.log(data);
},
error => {
console.log("Error");
console.log(error);
}
)
Run Code Online (Sandbox Code Playgroud)
该示例代码在Chrome,IE中可以正常运行,但是在Edge中则无法运行。我在Edge的Developer模式下检查了Network选项卡,似乎只发送了GET请求(不是我期望的POST请求,这很奇怪)。我在Edge中收到以下消息:
[对象对象]:{错误:对象,标头:对象,消息:“(未知URL)的HTTP错误响应:0未知错误”,名称:“ HttpErrorResponse”,确定:false ...}
错误:对象气泡:错误可取消:错误cancelBubble:错误currentTarget:null defaultPrevented:错误eventPhase:2 isTrusted:true length可计算:false加载:0 returnValue:true
srcElement:对象msCaching:“自动” onabort:null onerror:null onload:null onloadend:null onloadstart:null onprogress:null onreadystatechange:null ontimeout:null readyState:4响应:“” responseText:“” responseType:“文本” responseURL: “” 0:
目标:对象msCaching:“自动” onabort:空onerror:空onload:空onloadend:空onloadstart:空onprogress:空onreadystatechange:空ontimeout:空readyState:4响应:“” responseText:“” responseType:“文本” responseURL: “” 0:时间戳:30184.21007896917总计:0类型:“错误”
原型:对象
标头:对象
标头:对象大小:0
proto:对象lazyUpdate:null
normalizedNames:对象
proto:对象消息:“针对(未知URL)的HTTP故障响应:0未知错误”名称:“ HttpErrorResponse”确定:错误状态:0 statusText:“未知错误” URL:null
原型:对象
您是否有解决此问题的想法?
我正在开发Angular 6应用程序,我创建了一个带有一些输入的自定义组件。但是,当我传递false值时,将其视为true。这是我的自定义组件
<div class="row">
<div class="manager-actions col-md-12">
<div class="manager-actions__crud">
<button *ngIf="showAddButton" (click)="onAddClick($event)" type="button" class="btn btn-primary btn-icon">
<i class="nb-plus-circled"></i>
</div>
Run Code Online (Sandbox Code Playgroud)
我的组件类
export class TableActionsComponent implements OnInit {
constructor(private urlService: UrlManipulationService, private activatedRoute: ActivatedRoute, private actionService: TopbarActionsService) {
}
@Input() showDatePicker: boolean = false;
@Input() showAddButton: boolean = false;
@Input() showDeleteButton: boolean = false;
@Input() showPerPageSelector: boolean = false;
}
Run Code Online (Sandbox Code Playgroud)
我尝试如下使用
<ngx-table-actions showAddButton="false" showDeleteButton="true" showDatePicker="true"></ngx-table-actions>
Run Code Online (Sandbox Code Playgroud)
但是即使false设置也显示元素。