Define global constants

Below changes works for me on Angular 2 final version: export class AppSettings { public static API_ENDPOINT=’http://127.0.0.1:6666/api/’; } And then in the service: import {Http} from ‘angular2/http’; import {Message} from ‘../models/message’; import {Injectable} from ‘angular2/core’; import {Observable} from ‘rxjs/Observable’; import {AppSettings} from ‘../appSettings’; import ‘rxjs/add/operator/map’; @Injectable() export class MessageService { constructor(private http: Http) { } … Read more

How to get query parameters from URL in Angular 5?

In Angular 5, the query params are accessed by subscribing to this.route.queryParams (note that later Angular versions recommend queryParamMap, see also other answers). Example: /app?param1=hallo&param2=123 param1: string; param2: string; constructor(private route: ActivatedRoute) { console.log(‘Called Constructor’); this.route.queryParams.subscribe(params => { this.param1 = params[‘param1’]; this.param2 = params[‘param2’]; }); } whereas, the path variables are accessed by this.route.snapshot.params Example: … Read more

How should I use the new static option for @ViewChild in Angular 8?

In most cases you will want to use {static: false}. Setting it like this will ensure query matches that are dependent on binding resolution (like structural directives *ngIf, etc…) will be found. Example of when to use static: false: @Component({ template: ` <div *ngIf=”showMe” #viewMe>Am I here?</div> <button (click)=”showMe = !showMe”></button> ` }) export class … Read more

How to add bootstrap to an angular-cli project

IMPORTANT UPDATE: ng2-bootstrap is now replaced by ngx-bootstrap ngx-bootstrap supports both Angular 3 and 4. Update : 1.0.0-beta.11-webpack or above versions First of all check your angular-cli version with the following command in the terminal: ng -v If your angular-cli version is greater than 1.0.0-beta.11-webpack, then you should follow these steps: Install ngx-bootstrap and bootstrap: … Read more

Angular pass callback function to child component as @Input similar to AngularJS way

I think that is a bad solution. If you want to pass a Function into component with @Input(), @Output() decorator is what you are looking for. export class SuggestionMenuComponent { @Output() onSuggest: EventEmitter<any> = new EventEmitter(); suggestionWasClicked(clickedEntry: SomeModel): void { this.onSuggest.emit([clickedEntry, this.query]); } } <suggestion-menu (onSuggest)=”insertSuggestion($event[0],$event[1])”> </suggestion-menu>

How do I call an Angular 2 pipe with multiple arguments?

In your component’s template you can use multiple arguments by separating them with colons: {{ myData | myPipe: ‘arg1′:’arg2’:’arg3’… }} From your code it will look like this: new MyPipe().transform(myData, arg1, arg2, arg3) And in your transform function inside your pipe you can use the arguments like this: export class MyPipe implements PipeTransform { // … Read more

How to add font-awesome to Angular 2 + CLI project

After Angular 2.0 final release, the structure of the Angular2 CLI project has been changed — you don’t need any vendor files, no system.js — only webpack. So you do: npm install font-awesome –save In the angular-cli.json file locate the styles[] array and add font-awesome references directory here, like below: “apps”: [ { “root”: “src”, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)