Best Practices: Standalone Components vs. Modules in Angular 14 [closed]

Standalone components are not mandatory and will never be, there is no rule when to use them. However, Angular Architects recommend to always use Standalone components at least for new components you create. They are simply more treeshakeable and less boiler. You can mix standalone components and modules also. For the mentioned recommendation of the … Read more

Whats equivalent to ng-src in the newer Angular?

AngularJS: <img ng-src=”https://stackoverflow.com/questions/37965667/{{movie.imageurl}}”> Angular 2+: <img [src]=”movie.imageurl”> Angular docs Note that interpolation can achieve the same result: <img src=”https://stackoverflow.com/questions/37965667/{{vehicle.imageUrl}}”> <img [src]=”vehicle.imageUrl”> There is no technical difference between these two statements for property binding, as long as you don’t desire two-way binding. Interpolation is a convenient alternative for property binding in many cases. In fact, Angular … Read more

Command to Generate both a Routing Module & Component

There is no separate command to create routing.module file. But, that can be created while on the creation of the module: ng generate module [module-name] –routing or the shorthand version of the command: ng g m [module-name] –routing … will create the module and add the mappings/metadata linkings. I was searching about this a bit … Read more

How to proxy API requests to another server?

UPDATE 2022 The officially recommended approach is now the one documented here UPDATE 2017 Better documentation is now available and you can use both JSON and JavaScript based configurations: angular-cli documentation proxy sample https proxy configuration { “/angular”: { “target”: { “host”: “github.com”, “protocol”: “https:”, “port”: 443 }, “secure”: false, “changeOrigin”: true, “logLevel”: “info” } … Read more

Change the dist-folder path in angular-cli after ‘ng build’

The more current way of this is to update the outDir property in angular.json(called .angular-cli.json in old Angular CLI versions). The ng build command argument –output-path (or -op for short) is still supported also, which can be useful if you want multiple values, you can save them in your package.json as npm scripts. Beware: The … Read more

Module not found: Error: Can’t resolve ‘fs’ error

The error is because of angular-cli does not support modules in node like “fs” and “path”. (Issue) Add the following to the root of the “package.json” file. “browser”: { “fs”: false, “path”: false, “os”: false } Angular apps such as the ones Angular CLI creates are browser apps. fs isn’t available on the browser, it’s … Read more

Angular6 What’s browserTarget

browserTarget is a setting that maps a configuration to a build target e.g. build, serve, test, lint. It’s kind of a funny name. To be honest I don’t know why it’s called browserTarget instead of just target. Further reading here at the angular.io docs.

How to detect rxjs related memory leaks in Angular apps

Disclaimer: I’m the author of the tool I mention below. This can be accomplished by keeping a list where new subscriptions are added to, and removing subscriptions from this list once it is unsubscribed. The troublesome part is observing subscriptions. A straightforward way to achieve this is by monkey-patching the Observable#subscribe() method, that is, replacing … Read more