We created a directive in Angular2 and have an input property that should receive a string. The problem is that, we are not able to pass a string.

If we try to do this:

<learning-requirements [title]="You should be able to!" [content]="requirements"></learning-requirements>

It does not work, so we have to do this, and then it works:

<learning-requirements [title]="'You should be able to!'" [content]="requirements"></learning-requirements>

That is our directive:

@Component({
    selector: "learning-requirements",
    directives: [IONIC_DIRECTIVES],
    templateUrl: "build/pages/learning/components/requirements/requirements.html"
})
export class RequirementsComponent {
    @Input() public title: string;
    @Input("content") public items: Array<Requirement>;
}

Any idea how to handle string whithout explicitly using single quotation?

share|improve this question

Declare string(Type) variable and use it as shown below,

<learning-requirements [title]="someVar" [content]="requirements"></learning-requirements>


export class AppComponent{
  someVar:string="You should be able to!";
}
share
    
Ok, I know this, but is there a way to tell the directive that it's a string to avoid single quotes? – dag 5 mins ago
    
I don't understand what are you trying to say. What's your point after this answer? – micronyks 2 mins ago
    
If you don't want to use variable, you have to pass it with single quote. – micronyks 1 min ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.