In my Angular2 application, I have a straightforward form input component with an @Input
binding pointing to the attribute [dataProperty]
. The [dataProperty]
attribute holds a string value of this format:
[dataProperty]="modelObject.childObj.prop"
. The modelObject
is a model that is common throughout the application. This @Input
attribute allows me to pass the model from a parent component to my <custom-text-input>
component, where it is then connected by [ngModel]
to the nested component's input.
Everything functions as expected in my controller; when I access this.dataProperty
, I get the value on the model that the input binds to. However, I'm struggling to figure out how to retrieve the exact string passed to [dataProperty]
from the template.
Component:
@Component{
selector: "custom-text-input",
template: "<input type="text" [ngModel]="dataProperty"></input>
}
export Class customInputComponent implements OnInit {
@Input() dataProperty: string;
/**
Example of modelObject: { detail: { name: "Cornelius" } }
(^^^ would come from the parent component ^^^)
*/
constructor() {}
}
Use Case:
<div class=wrapper>
<custom-text-input [dataProperty]="modelObject.detail.name">
</custom-text-input>
</div>
When I try to access this.DataProperty
in the component controller, it returns "Cornelius". Is there a way to access the string literal so I can also capture the "modelObject.detail.name"
string from my controller?