Angular 4 HttpClient Query Parameters

I ended up finding it through the IntelliSense on the get() function. So, I’ll post it here for anyone who is looking for similar information. Anyways, the syntax is nearly identical, but slightly different. Instead of using URLSearchParams() the parameters need to be initialized as HttpParams() and the property within the get() function is now … Read more

Disable click outside of angular material dialog area to close the dialog (With Angular Version 4.0+)

There are two ways to do it. In the method that opens the dialog, pass in the following configuration option disableClose as the second parameter in MatDialog#open() and set it to true: export class AppComponent { constructor(private dialog: MatDialog){} openDialog() { this.dialog.open(DialogComponent, { disableClose: true }); } } Alternatively, do it in the dialog component … Read more

Angular 2.0 router not working on reloading the browser

The error you are seeing is because you are requesting http://localhost/route which doesn’t exist. According to Simon. When using html5 routing you need to map all routes in your app(currently 404) to index.html in your server side. Here are some options for you: using live-server: https://www.npmjs.com/package/live-server $live-server –entry-file=index.html` using nginx: http://nginx.org/en/docs/beginners_guide.html error_page 404 /index.html Tomcat … Read more

What are the practical differences between template-driven and reactive forms?

Template Driven Forms Features:” Easy to use Suitable for simple scenarios and fails for complex scenarios Similar to AngularJS Two way data binding(using [(NgModel)] syntax) Minimal component code Automatic track of the form and its data(handled by Angular) Unit testing is another challenge Reactive Forms Features: More flexible, but needs a lot of practice Handles … Read more

‘Found the synthetic property @panelState. Please include either “BrowserAnimationsModule” or “NoopAnimationsModule” in your application.’

Make sure the @angular/animations package is installed (e.g. by running npm install @angular/animations). Then, in your app.module.ts import { BrowserAnimationsModule } from ‘@angular/platform-browser/animations’; @NgModule({ …, imports: [ …, BrowserAnimationsModule ], … })

How to extend / inherit components?

Alternative Solution: This answer of Thierry Templier is an alternative way to get around the problem. After some questions with Thierry Templier, I came to the following working example that meets my expectations as an alternative to inheritance limitation mentioned in this question: 1 – Create custom decorator: export function CustomComponent(annotation: any) { return function … Read more

How to set without causing `unsafe value` exception?

Update v8 Below answers work but exposes your application to XSS security risks!. Instead of using this.domSanitizer.bypassSecurityTrustResourceUrl(url), it is recommended to use this.domSanitizer.sanitize(SecurityContext.URL, url) Update For RC.6^ version use DomSanitizer Plunker And a good option is using pure pipe for that: import { Pipe, PipeTransform } from ‘@angular/core’; import { DomSanitizer} from ‘@angular/platform-browser’; @Pipe({ name: … Read more

File Upload In Angular?

Angular 2 provides good support for uploading files. No third party library is required. <input type=”file” (change)=”fileChange($event)” placeholder=”Upload file” accept=”.pdf,.doc,.docx”> fileChange(event) { let fileList: FileList = event.target.files; if(fileList.length > 0) { let file: File = fileList[0]; let formData:FormData = new FormData(); formData.append(‘uploadFile’, file, file.name); let headers = new Headers(); /** In Angular 5, including the … Read more