我正在使用angular2创建一个应用程序。
我需要使用日历弹出窗口从用户输入中获取日期,但是我需要在用户输入上放置一个掩码,以使其在键入时保持dd-mm-YYYY的格式。
我正在使用从Web ng-bootstrap和angular2-text-mark获得的两个不同模块
<input [textMask]="{mask: mask}" type="text" class="form-control" placeholder="yyyy-mm-dd"
name="dp" [(ngModel)]="date" ngbDatepicker #d="ngbDatepicker">
Run Code Online (Sandbox Code Playgroud)
当我在同一标签上使用textMask和ngbDatepicker时,出现此错误
错误:多个自定义值访问器与具有未指定名称属性的表单控件匹配。
有办法做这种事情吗?
谢谢
我决定从React本周开始学习,因为针对该特定框架有很多工作。
我来自Angular的背景,发现自己想知道React中是否有与Angular的目的匹配的选项DatePipe。
我在我的angular6应用程序中使用rxjs6间隔。以下是我在angular6应用程序中实现间隔的代码。
app.component.ts
import { interval } from 'rxjs/observable/interval';
const source = interval(1000);
const subscribe = source.subscribe(val => console.log(val));
Run Code Online (Sandbox Code Playgroud)
一切正常,但是如何停止这个间隔?当我尝试取消订阅angular时说 source.unsubscribe is not a function
我想在(角度 5)中制作一个这样的可观察对象。如何responseType在 Angular 6 中声明?
Angular 5 代码:
public ExportSomeThing(
ano: number
): Observable<IDownloadArquivo> {
let q = this.http
.get(this.apiUrl + ano + '/pordia/excel', {
responseType: ResponseContentType.Blob // <<<-- This code
}).map((res) => {
Run Code Online (Sandbox Code Playgroud)
我的角度 6 代码:
public MyExport(
ano: number
): Observable<IXpto> {
let q = this.http
.get( this.api_rul + ano + '/some_path/', {
responseType: "ResponseContentType.Blob" // <<<--- error here !!!
}).map((res) => {
Run Code Online (Sandbox Code Playgroud)
错误是:
[ts]
Argument of type '{ responseType: "ResponseContentType.Blob"; }' is not assignable to …Run Code Online (Sandbox Code Playgroud) 我想要一种处理异常的通用方法,特别是从后端收到的 401。当我不提取 catchError 内容时,它工作正常。但是,如果我只是将其提取到特定函数,则该函数中不会注入任何内容:
return this.http.request<T>(new HttpRequest('POST', this.appConfig.baseApiPath + url, file, {
reportProgress: true,
headers: headers,
params: urlParams
})).pipe(
catchError((err) => {
if (err.status === 401) {
this.router.navigateByUrl('/login?expired=true');
}
return Observable.throw(err || 'Server error')
})
);
Run Code Online (Sandbox Code Playgroud)
这有效!但是我想在一个函数中处理这个重定向代码,以便通过其他方法重用它。
在这里,我将其导出到一个函数中:
return this.http.request<T>(new HttpRequest('POST', this.appConfig.baseApiPath + url, file, {
reportProgress: true,
headers: headers,
params: urlParams
})).pipe(
catchError(this.handleHttpError),
);
handleHttpError(error: HttpErrorResponse) {
if (error.status === 401) {
this.router.navigateByUrl('/login?expired=true'); --> router is null!
}
return Observable.throw(error || 'Server error')
}
Run Code Online (Sandbox Code Playgroud)
如果我使用这种工作方式,那就是路由器(以及其他构造函数注入的服务)为空的地方……你能建议为什么吗?
当我从 angular 6 项目上传图像时,我正在尝试按照教程将图像转换为 Base64。当我按下提交按钮时,我可以将输出作为值:“base64 代码”,并且我还可以通过使用“将 Base64 转换为图像”将代码转换为图像来获得相同的图像。但是在代码中,它显示“'string | ArrayBuffer'类型不存在属性'split'。'ArrayBuffer'类型不存在属性'split'。” 通过在红色下划线分割错误。我也尝试过类似的问题和答案。但它无法消除错误。
我的代码是
import {Component, ElementRef, ViewChild} from '@angular/core';
import {FormBuilder, FormGroup, Validators} from "@angular/forms";
@Component({
selector: 'base64-upload',
templateUrl: './base64-upload.component.html'
})
export class Base64UploadComponent {
form: FormGroup;
loading: boolean = false;
@ViewChild('fileInput') fileInput: ElementRef;
constructor(private fb: FormBuilder) {
this.createForm();
}
createForm() {
this.form = this.fb.group({
name: ['', Validators.required],
avatar: null
});
}
onFileChange(event) {
let reader = new FileReader();
if(event.target.files && event.target.files.length > 0) {
let file = event.target.files[0]; …Run Code Online (Sandbox Code Playgroud)正在开发的应用程序托管在iframe中.
我在我的应用程序中配置了以下路由:
const routes: Routes = [
{
path: '',
pathMatch: 'full',
redirectTo: 'list'
},
{
path: 'list',
component: ListComponent,
canActivate: [CanActivateRoute]
},
{
path: 'dashboard',
loadChildren: './modules/dashboard/dashboard.module#DashboardModule'
}
];
@NgModule({
imports: [RouterModule.forRoot(routes, { enableTracing: true })],
exports: [RouterModule],
providers: []
})
export class AppRoutingModule { }
Run Code Online (Sandbox Code Playgroud)
在ListComponent,OnInit方法,我用下面的代码来获取查询字符串PARAMS:
this.router.events.subscribe(val => {
if (val instanceof RoutesRecognized) {
console.log("val.state.root.firstChild.params: " + val.state.root.firstChild.params);
}
});
const firstParam: string = this.route.snapshot.queryParamMap.get('id');
Run Code Online (Sandbox Code Playgroud)
这些似乎都不起作用.我申请的网址如下:
https://company.com/#/app-dev/list?id=3
QueryParamMap或者RoutesRecongnized似乎没有在url中获取查询字符串"id = 3".它总是返回null.
任何人都可以帮我如何从角度应用程序中的URL检索查询参数/查询字符串?
从 Angular 5 升级到 Angular 7 时,我遇到了一些错误,例如 map 和 forkJoin 已弃用。但是这些错误都解决了。运行 ng serve 时仍然出现一个错误。
ERROR in ./node_modules/source-map-support/source-map-support.js
Module not found: Error: Can't resolve 'path' in 'D:\project\node_modules\source-map-support'
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助解决此错误。无法在下面的 package.json 中找出哪个包依赖于此
Package.json 如下
{
"name": "material",
"private": true,
"version": "1.0.0",
"main": "",
"scripts": {
"ng": "ng",
"start": "ng serve",
"hmr": "ng serve --hmr -e=hmr",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"clean": "rimraf node_modules",
"clean-all": "rimraf node_modules dist dll && npm cache clean",
"reinstall": "rimraf node_modules && …Run Code Online (Sandbox Code Playgroud) 对于基于Web的POS(销售点),没有什么比立即打印账单更为必要的。但是,如何从网页直接命令打印机没有太多选择?-特别是在开发时使用Angular框架。我在网络上到处搜索,但一无所获。
是否有任何第三方图书馆或完成我的目标的东西?
我检查了全局包 minimatch 的 gulp
$ npm list -g minimatch
+-- gulp@3.9.1
| `-- vinyl-fs@0.3.14
| +-- glob-stream@3.1.18
| | +-- glob@4.5.3
| | | `-- minimatch@2.0.10 deduped
| | `-- minimatch@2.0.10
| `-- glob-watcher@0.0.6
| `-- gaze@0.5.2
| `-- globule@0.1.0
| +-- glob@3.1.21
| | `-- minimatch@0.2.14 deduped
| `-- minimatch@0.2.14
Run Code Online (Sandbox Code Playgroud)
现在,我想将特定 gulp 包(所有 minimatch@0.2.14 和 minimatch@3.04)中的所有 minimatch 版本更新到最新版本。
npm 中是否有任何命令可以更新我现有的包依赖项?
angular ×9
angular6 ×2
angular7 ×2
npm ×2
angular5 ×1
base64 ×1
gulp ×1
httpclient ×1
javascript ×1
maskedinput ×1
minimatch ×1
ng-bootstrap ×1
node.js ×1
printing ×1
reactjs ×1
response ×1
rxjs ×1
split ×1
typescript ×1