angular5

Angular Service Worker - dataGroups not working

荒凉一梦 提交于 2019-12-22 05:20:09
问题 I'm trying to use Angular Service Worker, everything works fine except the dataGroups not working for me. that's what I have in my ngsw-config.json : "dataGroups": [ { "name": "api-performance", "urls": [ "/shipments/**" ], "cacheConfig": { "strategy": "performance", "maxSize": 100, "maxAge": "3d" } } ] In my network tab I see that the service worker always make the server call then falls back to the cache. see attached image. dataGroups - Performance Notice the API I'm calling are on a

How to use Lodash when data is undefined or null

谁都会走 提交于 2019-12-22 05:19:42
问题 In my application If data is undefined or null which is coming from service, my html will not load and I will get "data is undefined" error so I am tring to use lodash, but dont know how to use it.. In my below ts file this._PartService.GetDataValues().subscribe( result => { this.distributionData = this._PartService.part_data.partMasterDataCompleteList[0].partMasterData.plantSupplies.plantSupply } I will be getting "partMasterDataCompleteList" as undefiend or null if data is not there, so

How override Provider in Angular 5 for only one test?

半世苍凉 提交于 2019-12-22 03:51:32
问题 In one of my unit test files, I have to mock several times the same service with different mocks. import { MyService } from '../services/myservice.service'; import { MockMyService1 } from '../mocks/mockmyservice1'; import { MockMyService2 } from '../mocks/mockmyservice2'; describe('MyComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [ MyComponent ], providers: [ { provide: MyService, useClass: MockMyService1 } ] }) .compileComponents(); }));

Angular 5 Service Worker not working

╄→гoц情女王★ 提交于 2019-12-22 03:09:28
问题 I try to add service worker to my project after updating to angular 5 and have some problems. I add imports to app.module.ts: import {ServiceWorkerModule} from '@angular/service-worker'; import {environment} from '../environments/environment'; ... environment.production ? ServiceWorkerModule.register('/ngsw-worker.js') : [], execute $ ng set apps.0.serviceWorker=true to allow service workers in project generate config: { "index": "/index.html", "assetGroups": [ { "name": "app", "installMode":

Angular 5 and ExcelJS

泄露秘密 提交于 2019-12-22 01:15:40
问题 I have been trying to use and following the examples from this library: https://www.npmjs.com/package/exceljs#create-a-workbook I am using it on Angular 5. I always get an error graceful-fs.js:166 Uncaught TypeError: Cannot read property 'prototype' of undefined at patch (graceful-fs.js:166) From these lines of my code: import * as Excel from 'exceljs'; export class ExcelHandler { public testExcelJs() { var workBook: Excel.Workbook; var workSheet: Excel.Worksheet; workBook = new Excel

Angular 5: Response for preflight has invalid HTTP status code 403

强颜欢笑 提交于 2019-12-21 20:33:47
问题 When I send a POST request to the server I get an error: Failed to load http://localhost:8181/test: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. The response had HTTP status code 403. The backend is written in Java Spring. My method for creating a test: createTest() { const body = JSON.stringify({ 'description': 'grtogjoritjhio',

Angular Service Worker on the browsers that do not support it

倖福魔咒の 提交于 2019-12-21 17:51:52
问题 Angular team made a great job and introduced service workers support in the version 5. The documentation is quite helpful and I can really see how the things will work right after reading the related articles, however there is one topic that is not covered there. How does this all work in the browsers that do not support service workers. This is what's being said: Your application must run in a web browser that supports service workers. Currently, the latest versions of Chrome and Firefox are

disable the button if the input is empty

断了今生、忘了曾经 提交于 2019-12-21 12:49:28
问题 How can I disable the button if the input is empty, and enable it when the user start typing in the input, i tried that: <input #new_field type="text" autocomplete="off" /> <p-button (onClick)="saveNewField(new_field.value)" [disabled]="new_field.value ==''" label="Save"></p-button> and also this: <input [(ngModel)]="searchText" size="30" autocomplete="off" /> <p-button (onClick)="saveNewField(searchText)" [disabled]="!searchText" label="Save"></p-button> 回答1: Use ngModel and bind a value and

(TypeError: Cannot read property 'length' of null at HttpHeaders.applyUpdate) Angular 5, Http Client

天涯浪子 提交于 2019-12-21 11:30:07
问题 I'm getting this reponse when making an http request in service. Here's the Login component export class LoginComponent { credentials: Credentials; constructor( private auth: AuthService, @Inject(UserService) private userService: UserService, @Inject(HttpClient) private http: HttpClient, private auth0: Auth0Service ) {} onLogin(credentials) { const sendReq = this.userService.login(credentials); } I've added UserService in providers in App.module Here's the UserService @Injectable() export

(TypeError: Cannot read property 'length' of null at HttpHeaders.applyUpdate) Angular 5, Http Client

若如初见. 提交于 2019-12-21 11:30:02
问题 I'm getting this reponse when making an http request in service. Here's the Login component export class LoginComponent { credentials: Credentials; constructor( private auth: AuthService, @Inject(UserService) private userService: UserService, @Inject(HttpClient) private http: HttpClient, private auth0: Auth0Service ) {} onLogin(credentials) { const sendReq = this.userService.login(credentials); } I've added UserService in providers in App.module Here's the UserService @Injectable() export