angular-cli
Angular tests failing with Failed to execute ‘send’ on ‘XMLHttpRequest’
This is a problem of the new Angular Cli. Run your test with –sourcemaps=false and you will get the right error messages. See details here: https://github.com/angular/angular-cli/issues/7296 EDIT: Shorthand for this is: ng test -sm=false As of angular 6 the command is: ng test –source-map=false
angular-cli server – how to specify default port
Update for @angular/cli@9.x: and over In angular.json you can specify a port per “project” “projects”: { “my-cool-project”: { … rest of project config omitted “architect”: { “serve”: { “options”: { “port”: 1337 } } } } } All options available: https://angular.io/guide/workspace-config#project-tool-configuration-options Alternatively, you may specify the port each time when running ng serve like this: … Read more
How to iterate using ngFor loop Map containing key as string and values as map iteration
For Angular 6.1+ , you can use default pipe keyvalue ( Do review and upvote also ) : <ul> <li *ngFor=”let recipient of map | keyvalue”> {{recipient.key}} –> {{recipient.value}} </li> </ul> WORKING DEMO For the previous version : One simple solution to this is convert map to array : Array.from Component Side : map = … Read more
“Error: No provider for router” while writing Karma-Jasmine unit test cases
You need to import RouterTestingModule when setting up the test module. /* tslint:disable:no-unused-variable */ import { async, ComponentFixture, TestBed } from ‘@angular/core/testing’; import { By } from ‘@angular/platform-browser’; import { DebugElement } from ‘@angular/core’; import { RouterTestingModule } from ‘@angular/router/testing’; import { MyNewComponentComponent } from ‘./my-new-component.component’; describe(‘MyNewComponentComponent’, () => { let component: MyNewComponentComponent; let fixture: … Read more
Message “the term ‘ng’ is not recognized as the name of a cmdlet”
The first path in the path variable needs to be the NPM path. Opening the Node.js command prompt I found that the ng command worked there. I dug into the shortcut and found that it references a command to ensure the first Path variable is NPM. To Fix: Right Clicked on My Computer (windows) Selected … Read more
How to change Angular CLI favicon
Make a png image with same name (favicon.png) and change the name in these files: index.html: <link rel=”icon” type=”image/x-icon” href=”https://stackoverflow.com/questions/40817280/favicon.png” /> angular-cli.json: “assets”: [ “assets”, “https://stackoverflow.com/questions/40817280/favicon.png” ], And you will never see the angular default icon again. Size should be 32×32, if more than this it will not display. NOTE: This will not work with … Read more
ERROR in The Angular Compiler requires TypeScript >=3.1.1 and
To fix this install the specific typescript version 3.1.6 npm i typescript@3.1.6 –save-dev –save-exact
How to decrease prod bundle size?
Update February 2020 Since this answer got a lot of traction, I thought it would be best to update it with newer Angular optimizations: As another answerer said, ng build –prod –build-optimizer is a good option for people using less than Angular v5. For newer versions, this is done by default with ng build –prod … Read more
ng: command not found while creating new project using angular-cli
The issue is simple, npm doesn’t know about ng Just run npm link @angular/cli and it should work seamlessly.