1

How do you implement one-way binding? Please provide some explanation on why and when you would use one-way binding.

I'm new to AngularJS.

Sarhanis
  • 1,577
  • 1
  • 12
  • 19
Brandon Michael Hunter
  • 1,179
  • 3
  • 20
  • 48
  • angular is realtime two way data binding framework, you can bind your data in `ng-bind` or in `{{ expression }}` – ojus kulkarni Feb 29 '16 at 00:37
  • Possible duplicate of [How does data binding work in AngularJS?](http://stackoverflow.com/questions/9682092/how-does-data-binding-work-in-angularjs) – Satej S Feb 29 '16 at 04:33

1 Answers1

0

Please provide some explanation on why and when you would use one-way binding.

Possible Reasons:

  1. You want to speed up your app.
  2. You want your Angular 1 to have an easier upgrade path to Angular 2
  3. You have a value that you want to pass to several children, but when the children change the value, you don't want the other children to sync this change.

How do you implement one-way binding?

Before Angular 1.5 you can make a make a deep copy of your object with angular.copy once you pass it in, so e.g. myVal = angular.copy(myVal). After Angular 1.5, you can use < in your bindings, which would then look like that:

bindings: {
  myVal: "<"
}

However, note that if myVal is an object, you'll still have to do the deep copy using angular.copy, the "<" only works for non-object values. See the following plunkr to see what I mean.

bersling
  • 17,851
  • 9
  • 60
  • 74