标签: angular5

Angular 5:警告承诺被拒绝

我刚刚使用angular-cli安装了Angular 5:

在新的应用程序中,以下警告将在控制台中进行吐出.

不知道原因是什么?

h1.js:25 Warning: a promise was rejected with a non-error: [object String]
     at g (chrome-extension://bmnlcjabgnpnenekpadlanbbkooimhnj/h1.js:25:11246)
     at i.n._warn (chrome-extension://bmnlcjabgnpnenekpadlanbbkooimhnj/h1.js:25:15804)
     at i._rejectCallback (chrome-extension://bmnlcjabgnpnenekpadlanbbkooimhnj/h1.js:25:45600)
     at Function.i.reject.i.rejected (chrome-extension://bmnlcjabgnpnenekpadlanbbkooimhnj/h1.js:25:41344)
     at chrome-extension://bmnlcjabgnpnenekpadlanbbkooimhnj/h1.js:39:63684
     at i (chrome-extension://bmnlcjabgnpnenekpadlanbbkooimhnj/h1.js:25:72787)
     at i._settlePromiseFromHandler (chrome-extension://bmnlcjabgnpnenekpadlanbbkooimhnj/h1.js:25:46193)
     at i._settlePromise (chrome-extension://bmnlcjabgnpnenekpadlanbbkooimhnj/h1.js:25:46993)
     at i._settlePromise0 (chrome-extension://bmnlcjabgnpnenekpadlanbbkooimhnj/h1.js:25:47692)
     at i._settlePromises (chrome-extension://bmnlcjabgnpnenekpadlanbbkooimhnj/h1.js:25:49019)
     at o._drainQueue (chrome-extension://bmnlcjabgnpnenekpadlanbbkooimhnj/h1.js:25:2790)
     at o._drainQueues (chrome-extension://bmnlcjabgnpnenekpadlanbbkooimhnj/h1.js:25:2851)
     at drainQueues (chrome-extension://bmnlcjabgnpnenekpadlanbbkooimhnj/h1.js:25:984)
     at <anonymous>
Run Code Online (Sandbox Code Playgroud)

promise angular angular5

2
推荐指数
1
解决办法
744
查看次数

Angular 5 HttpInterceptor this.interceptor.intercept不是一个函数

我创建了一个HttpInterceptor(Angular5),以便为每个xhr请求添加"withCredentials:true".但每次我调用任何http请求时,都会收到以下错误:

ERROR TypeError: this.interceptor.intercept is not a function
at HttpInterceptorHandler.handle (http.js:1777)
at HttpXsrfInterceptor.intercept (http.js:2470)
at HttpInterceptorHandler.handle (http.js:1777)
at MergeMapSubscriber.eval [as project] (http.js:1447)
at MergeMapSubscriber._tryNext (mergeMap.js:128)
at MergeMapSubscriber._next (mergeMap.js:118)
at MergeMapSubscriber.Subscriber.next (Subscriber.js:91)
at ScalarObservable._subscribe (ScalarObservable.js:51)
at ScalarObservable.Observable._trySubscribe (Observable.js:172)
at ScalarObservable.Observable.subscribe (Observable.js:160)
Run Code Online (Sandbox Code Playgroud)

import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from "@angular/common/http";
import {Observable} from "rxjs/Observable";
import {Injectable} from "@angular/core";

@Injectable()
export class GeneralInterceptor implements HttpInterceptor{
    intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
        const cRequest = req.clone({
            withCredentials: true
        });
        return next.handle(cRequest);
    }
}
Run Code Online (Sandbox Code Playgroud)

这是app.moudle.ts

angular-http-interceptors angular angular5

2
推荐指数
1
解决办法
3757
查看次数

设置后无法启用产品模式

当我尝试在Stack Blitz中启用产品模式时,有时会告诉我

设置后无法启用产品模式

https://stackblitz.com/edit/angular-gitter-fv1bhs

angular angular5

2
推荐指数
1
解决办法
654
查看次数

无法从angular4中的嵌套函数访问此函数

我有一个名为abc的组件,并且在该组件中有三个名为title,Desc,Name的变量,当我尝试从嵌套函数访问它时,它给了我未定义的含义。

例如

@Component({
  selector: 'abc',
  templateUrl: './abc.component.html',
  styleUrls: ['./abc.component.css'],
  providers: [abcService]
})

export class abcComponent implements AfterViewInit,AfterViewChecked {

  title;
  Desc;
  Name;
  date=null;

test(){
this.title='a';
//work fine
}

test11(){

$('#cmg tbody').on('click', 'a.editor_edit', function (e) {
e.preventDefault();
this.title= false;  //gives me an undefined
});

}

}
Run Code Online (Sandbox Code Playgroud)

javascript jquery angular2-services angular angular5

2
推荐指数
1
解决办法
1178
查看次数

将Angular 5更新为Angular 6错误

我刚从角度5更新到角度6,我面临角度动画的问题.

我做了标准升级

npm install -g @angular/cli
npm install @angular/cli
ng update @angular/cli --migrate-only --from=1.7.4
ng update @angular/core
npm install rxjs-compat (most project probably need this)
ng serve
Run Code Online (Sandbox Code Playgroud)

我还根据官方升级指南(https://update.angular.io/)从5.2到6 更新了我的代码库,但是有一个错误,我无法弄清楚.

ERROR in src/app/dispute-center/shared/services/dispute-store-service.ts(1,22): error TS2305: Module '"/var/www/html/xxx-angular/node_modules/@angular/core/core"' has no exported member 'transition'.

src/app/profile/profile-payments-and-billing/profile-payments-and-billing.component.ts(1,28): error TS2305: Module '"/var/www/html/xxx-angular/node_modules/@angular/core/core"' has no exported member 'trigger'.

src/app/profile/profile-payments-and-billing/profile-payments-and-billing.component.ts(1,37): error TS2305: Module '"/var/www/html/xxx-angular/node_modules/@angular/core/core"' has no exported member 'state'.

src/app/profile/profile-payments-and-billing/profile-payments-and-billing.component.ts(1,44): error TS2305: Module '"/var/www/html/xxx-angular/node_modules/@angular/core/core"' has no exported member 'style'.

src/app/profile/profile-payments-and-billing/profile-payments-and-billing.component.ts(1,51): error TS2305: Module '"/var/www/html/xxx-angular/node_modules/@angular/core/core"' has no …
Run Code Online (Sandbox Code Playgroud)

angular2-template angular2-routing angular angular5 angular6

2
推荐指数
1
解决办法
3967
查看次数

Angular 6迁移PWA无法正常工作

我最近将我的应用程序迁移到Angular 6,它在角度5中运行良好,我遇到了很多问题,但无论如何我解决了它们,但PWA我无法迁移,在角度5 PWA工作正常,但在6给出以下错误......

当我跑步的时候

    command ng add @angular/PWA  its showing error 
**Error ** 
    target is not defined for the specified project 
Run Code Online (Sandbox Code Playgroud)

请帮助如何在Angular 6中迁移或添加PWA

angular5 angular6

2
推荐指数
1
解决办法
1797
查看次数

无法读取未定义的属性'schedule'

所需的输出是BsDatePicker,由于某种原因给我错误:无法读取未定义的属性'schedule'.
并且还有警告BsDatepickerModule正在开发中,BREAKING CHANGES是可能的,PLEASE,读取changelog

Angular-CLI版本1.7.4,ngx-bootstrap版本3.0.0,Angular 5

这是html
<input type="text" [(ngModel)]="dateOfBirth" name="dateOfBirth" id="dateOfBirth" bsDatepicker class="form-control"/>

的代码: 这是代码app.module.ts:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { BsDatepickerModule } from 'ngx-bootstrap/datepicker';
import { AppRoutingModule } from './app-routing.module';

import { AppComponent } from './app.component';
import { HomeComponent } from './home/home.component';
import { PageNotFoundComponent } from './page-not-found/page-not-found.component';
import { CreateEmployeeComponent } from './employee/create-employee/create-employee.component';


@NgModule({
  declarations: [
    AppComponent,
    HomeComponent,
    CreateEmployeeComponent,
    PageNotFoundComponent …
Run Code Online (Sandbox Code Playgroud)

web-frontend ngx-bootstrap angular angular5

2
推荐指数
1
解决办法
3854
查看次数

Angular 6:无法读取未定义的属性“ get”

我正在使用Angular进行练习,尝试使用“内置验证器”时遇到问题。我尝试将表单字段的值作为参数传递,但是当我尝试执行此操作时,我只是看到标题为“无法读取未定义的属性'get'的未定义”的错误信息:

form.component.ts

this.form = new FormGroup({
      'name': new FormControl(this.name, [
        Validators.required,
        Validators.minLength(4),
        forbiddenNameValidator(this.name)
      ]),
      'alterEgo': new FormControl(this.alterEgo),
      'power': new FormControl(this.power, Validators.required)
    });
Run Code Online (Sandbox Code Playgroud)

...更多代码...

get name(): string { return this.form.get('name').value };
get power(): string { return this.form.get('power').value };
Run Code Online (Sandbox Code Playgroud)

当我尝试将forbiddenNameValidator(this.name)方法作为参数发送时,出现该错误。

form.component.html

<form [formGroup]="form" (ngSubmit)="Ver()">
<div class="form-group">
   <label for="name">Name</label>
   <input type="text" class="form-control" name="name" formControlName="name">
</div>
</form>
Run Code Online (Sandbox Code Playgroud)

这是我得到的错误:

在此处输入图片说明

custom-validators angular angular5 angular6

2
推荐指数
1
解决办法
4315
查看次数

在typescript Angular 5中导入json文件

我试图在typescript类中导入json文件

import * as nationalities from './mock/nationalities.json';
Run Code Online (Sandbox Code Playgroud)

它给了我一个错误

找不到模块'./mock/nationalities.json'.

为了解决这个问题,我添加了这个

declare module '*.json' {
  const value: any;
  export default value;
}
Run Code Online (Sandbox Code Playgroud)

但它没有解决我的问题,也给了我另一个错误异常

增强中的模块名称无效,无法找到模块'*.json'.

我的打字稿版本

2.9.2

typescript ionic2 ionic3 angular angular5

2
推荐指数
1
解决办法
4543
查看次数

从子组件到父组件的Angular 5 EventEmitter发出未定义

我正在尝试将一个string从子组件发送到他的父组件。

这是孩子:

//imports... 

    @Component({
    selector: 'child',
    templateUrl: './child.component.html',
    styleUrls: ['./child.component.css'],
    providers: [ChildService]
    })

export class DataTableComponent implements OnInit {
    constructor(private http: HttpClient, private childService : ChildService) {}

    myMap = new Map<string, ISomeInterface>();
    currentSelection: string;

    @Output() sendDataEvent = new EventEmitter<string>();

    sendData() {
        console.log("sending this data:  " + this.myMap.get(this.currentSelection).name);
        this.sendDataEvent.emit(this.myMap.get(this.currentSelection).name);
    }
}
Run Code Online (Sandbox Code Playgroud)

这是父母:

html->

<d-table (sendDataEvent)="receiveBusinessCycle(event)"></d-table>
Run Code Online (Sandbox Code Playgroud)

打字稿->

//imports...

@Component({
  selector: 'parent',
  templateUrl: './parent.component.html',
  styleUrls: ['./parent.component.css'],
  providers: [ParentService]
})
export class MyParentComponent {
  totoName: string;

  constructor(private parentService : ParentService) {  } …
Run Code Online (Sandbox Code Playgroud)

typescript angular angular5

2
推荐指数
1
解决办法
2291
查看次数