I have a simple form input component in my angular2 app which contains an @Input
binding to the attribute [dataProperty]
. As you may have guessed, the [dataProperty]
attribute is a string value of the format: [dataProperty]="modelObject.childObj.prop"
, where the modelObject
is the model shared throughout my application. Basically, I'm using this @Input
attribute to pass the model from a parent component to my <custom-text-input>
component, where it is then bound by [ngModel]
to the nested component's input.
Everything works as intended and in my controller; i.e. when I access this.dataProperty
the value on the model to which the input binds is returned. What I can't seem to find out, however, is how to access the string literal passed to [dataProperty]
from the template in the first place.
Component:
@Component{
selector: "custom-text-input",
template: "<input type="text" [ngModel]="dataProperty"></input>
}
export Class customInputComponent implements OnInit {
@Input() dataProperty: string;
/**
ex of modelObject: { detail: { name: "Cornelius" } }
(^^^ would originate in parent component ^^^)
*/
constructor() {}
}
Use Case:
<div class=wrapper>
<custom-text-input [dataProperty]="modelObject.detail.name">
</custom-text-input>
</div>
Basically, when I go to access this.DataProperty
from the component controller it returns "Cornelius". Is it possible to access the string literal so that I can capture the "modelObject.detail.name"
string from my controller as well?