D.B
D.B

Reputation: 4289

Property binding to a service function - angular

Is it possible to bind a property to a service function?

I am trying something like this:

View:

<app-grid [header]=namingConventionService.getResourceText("something")></app-grid>

In the Service:

getResourceText(key: string) {
if (this.namingConvention) {
  return this.namingConvention[key];
}

}

I get a console error: Template parse errors: Unexpected closing tag...

Upvotes: 0

Views: 129

Answers (2)

Barremian
Barremian

Reputation: 31115

Yes, try enclosing the function in quotes.

<app-grid [header]="namingConventionService.getResourceText('something')"></app-grid>

Notice the single quotes surrounding something. That is how constant literals are used in templates.

Upvotes: 2

Martin Parenteau
Martin Parenteau

Reputation: 73731

Enclose the binding in double quotes, and the inner string in single quotes:

[header]="namingConventionService.getResourceText('something')"

Upvotes: 0

Related Questions