_bug_
When you try to use one way binding in angular 1.5.5 for an Object in a component
for example:
angular.module('heroApp').component('heroDetail', {
templateUrl: 'heroDetail.html',
controller: HeroDetailController,
bindings: {
hero: '<' //One Way Binding Object
}
});
function HeroDetailController() {
var ctrl = this;
//Bug here
ctrl.hero.location = "location"
}
When you try to edit the hero Object for example: hero.location = 'location', it will affect the parent Object. So the hero object in the parent will have this new property called location and has the value of 'location'
https://plnkr.co/edit/5kGPXdTCXGK3xGLCFMkJ?p=preview
The original object should not be modified
Angular: 1.5.5
How do I use the codes?
This is actually mentioned as a caveat of using one-way bindings in the docs, so I'm pretty sure this is the intended behavior.
one-way binding does not copy the value from the parent to the isolate scope, it simply sets the same value. That means if your bound value is an object, changes to its properties in the isolated scope will be reflected in the parent scope (because both reference the same object).
Yes, it's intended behavior. One-way binding doesn't make the object immutable, nor does it create a copy of it.
Thx @17cupsofcoffee !
@gkalpak it doesn't but it should be
Most helpful comment
@gkalpak it doesn't but it should be