angular6

Angular 6 View is not updated after changing a variable within subscribe

心已入冬 提交于 2019-12-04 09:02:37
问题 Why is the view not being updated when a variable changes within a subscribe? I have this code: example.component.ts testVariable: string; ngOnInit() { this.testVariable = 'foo'; this.someService.someObservable.subscribe( () => console.log('success'), (error) => console.log('error', error), () => { this.testVariable += '-bar'; console.log('completed', this.testVariable); // prints: foo-Hello-bar } ); this.testVariable += '-Hello'; } example.component.html {{testVariable}} But the view

Angular Material v6 Mat-Footer - “Cannot read property 'template' of undefined”

£可爱£侵袭症+ 提交于 2019-12-04 08:35:58
I'm trying to implement a footer row into a mat-table component after recently upgrading to angular 6 for this purpose, but after adding both the mat-footer-cell and mat-footer-row elements in the table, I get the following error: ERROR TypeError: Cannot read property 'template' of undefined at MatFooterRowDef.push../node_modules/@angular/cdk/esm5/table.es5.js.CdkFooterRowDef.extractCellTemplate (vendor.js:17400) The table still appears on the page, but with no data, no footer row, and a T symbol where to the right of each column heading. HTML: <ng-container matColumnDef="total"> <mat-header

Can't update angular to version 6

蹲街弑〆低调 提交于 2019-12-04 07:21:01
I'm trying to update angular to latest version . I have updated global @angular/cli npm install -g @angular/cli Then when I try to update local @angular/cli using ng update @angular/cli I get this error: Error: Unexpected end of JSON input Unexpected end of JSON input Here's my package.json { "name": "apimap", "version": "0.0.0", "license": "MIT", "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e" }, "private": true, "dependencies": { "@angular/animations": "^5.2.11", "@angular/cdk": "^5.2.5", "@angular/common": "^5.2.11", "

How to inject snackBarRef into a component with openFromComponent

空扰寡人 提交于 2019-12-04 07:19:10
The latest Material documentation says the following.. If you want to close a custom snack-bar that was opened via openFromComponent, from within the component itself, you can inject the MatSnackBarRef. but they don't show you how to do it. In their example, they nest a component within the same .ts file as the calling module, and they don't show the ref being passed in. But since I want to use a more centralized approach, I have created a new module using... ng g component components/snackbar This way, I should be able to pass in @Input to render different html depending on need. This would

send synchrouns request angular 6 [closed]

↘锁芯ラ 提交于 2019-12-04 07:08:21
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 7 months ago . i want to send synchrouns request this nested for loop in angular 6. it all for loop must wait each other response. Please give some example in https://stackblitz.com protected plateInfo(debug = true) { for (let i = 0; i < 8; i++) { for (let k = 0; k < 8; k++) { if (k % 2 !== 0) { for (let

Angular 6 How To Get Values From Multiple Checkboxes and Send in From

帅比萌擦擦* 提交于 2019-12-04 06:30:17
问题 I'm trying to use mat-checkboxes as input in my form, but can't really find anything on docs regarding it. Html <section class="checkbox-section"> <mat-checkbox [(ngModel)]="bChecked">Blogs</mat-checkbox> <mat-checkbox [(ngModel)]="wChecked">Web</mat-checkbox> <mat-checkbox [(ngModel)]="oChecked">Online News</mat-checkbox> </section> Typescript public form = { name: null, email: null, birthday: null, company: null, interests: [], newsletter: null, address: null, password: null, password

Angular httpClient interceptor error handling

*爱你&永不变心* 提交于 2019-12-04 06:16:17
after reading the documentation on angular about http client error handling, I still don't understand why I don't catch a 401 error from the server with the code below: export class interceptor implements HttpInterceptor { intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { console.log('this log is printed on the console!'); return next.handle(request).do(() => (err: any) => { console.log('this log isn't'); if (err instanceof HttpErrorResponse) { if (err.status === 401) { console.log('nor this one!'); } } }); } } on the console log, I also get this: zone.js

ckeditor is undefined in Angular 6

99封情书 提交于 2019-12-04 05:44:58
问题 I am using ckeditor in Angular 6. And trying to create a instance while uploading image saveToServer(file: File) { this.appService.saveEditorimage(file).subscribe(data => { this.response = data.json(); var url = "/images/" + this.response[0].filename console.log(url) // this.ckEditor let link = this.ckEditor.instance.document.createElement("img"); link.setAttribute("alt", "Image"); link.setAttribute("src", url); this.ckEditor.instance.insertElement(link); }) } this.ckEditor is undefined. How

resetting reactive form triggers all required validators in Angular 6

拈花ヽ惹草 提交于 2019-12-04 03:51:20
问题 I am new to angular 6 ,Here I am trying to reset the form after submitting the data. Everything works fine but when I reset the form after successful data submit to database it triggers all the required validators in the form. I tried many ways to solve this but I couldn't solve it . Here after each form submission I want to reset the form and all the validators before enter the data in form fields for another submission. app.component.html <form [formGroup]="newMemberForm" (submit)=

How to use environment variable in index.html for Angular 6

佐手、 提交于 2019-12-03 23:44:05
I am using angular6, in my project I am using Facebook Account Toolkit for mobile verification purpose. I need to initialise Account toolkit in index.html file using following code. AccountKit.init({ appId:"XX", state:"xx", version:"v1.2", fbAppEventsEnabled:true, debug:true }); The problem is, values for appId and state change depending on environment (development/test/production). How can I use environment variables in index.html file. Please let me know if anyone has a solution for angular 6. Thanks in advance. Artyom Krasnyuk You should create copy of index.html and name it index.someenv