1

I am trying to assign a formatted value, the below code is woking fine

export class AppComponent {
  public urlObj = this._urlService.get('GET_CLIENT_ID');
  url = this._urlService.formatURL('root', this.urlObj.URL);
  constructor(private _urlService: UrlService) {
  }
 }

But when I try to directly change urlObj.URL its not working like

export class AppComponent {
  public urlObj = this._urlService.get('GET_CLIENT_ID');
  this.urlObj.URL = this._urlService.formatURL('root', this.urlObj.URL);
  constructor(private _urlService: UrlService) {
  }
}

It is saying Unexpected token at this.urlObj

1
  • You can't use this outside of class methods Commented Jan 18, 2017 at 7:40

1 Answer 1

2

Your _urlService is initialized at constructor level. Try doing the assignment operation inside it:

export class AppComponent {
  public urlObj; 

  constructor(private _urlService: UrlService) {
   this._urlService.get('GET_CLIENT_ID');
   this.urlObj.URL = this._urlService.formatURL('root', this.urlObj.URL);
  }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.