Reputation: 5011
In angular 1.x, one-way databinding syntax was ::
I'm trying to pass an object down to a child component with one-time binding. The child needs to get the initial data from the parent, but the parent doesn't ever change the data and doesn't need to know if the child changed it.
<parent [child-data]="childData"/>
How can I one-time bind this?
Upvotes: 6
Views: 4896
Reputation: 550
I had the same problem. In my case was enough to add an additional Input() set
and save the new value only if the old one wasn't set yet
@Input() set initChildData(initChildData: any) {
if (initChildData && this.childData == undefined) {
this.childData = initChildData;
}
}
Then in html just call [initChildData]
instead of [child-data]
You can use it in one component for one Input or just move it to an abstract BaseComponent class to make it more generic
Upvotes: 0
Reputation: 1405
I know this is old, but I stumbled upon this: ANGULAR CHANGE DETECTION EXPLAINED which basically says that as long as you use immutable inputs and observables (which might not be the case all the time, but it could be in some big tables with lots of bindings):
@Input
, then you got One time binding yeah I know it's for the whole component, not just for specific bindings though....Upvotes: 1
Reputation: 4058
This post: angular 2 one time binding seams to indicate the using ChangeDetectionStrategy.CheckOnce could be the solution.
Upvotes: 1