0
Hello, I’m having a hard time getting information between 2 components working with Angular 1. This is my example:
angular.module("parent",["child"]).component("parent",{
template : "<p> <child name></child> </div>",
controllerAs:"parent",
controller : {
constructor(){}
}
});
angular.module("child",[]).component("child",{
binding : {
"name" = "="
}
template : "<span>{{name}}</span>",
controllerAs : "child",
controller : {
constructor(){
this.name = name;
}
}
});
So far, in case I enter the value manually in <child name="foo"></child>
the component Child has its contents changed. The problem is that I’m not understanding how through the Parent i will be able to change the content of the component name parameter Child
Could someone explain to me?
in that case, if I pass the Binding as
"<"
i will be able to change only what was from Parent to Child? I arrived at a similar solution but, when changing Child, Parent also changed...– LeandroLuk
@Leandroluk Yes, that’s how you distinguish a component Dumb of a component smart, if you use the
<
, any change that needs to be made will have to be delegated to the parent component.– lenilsondc
but then how can I have a Parent-only traffic lane for Child? I cannot change Parent because it is a direct Mutateobserver in mongodb, that is, it will change when it understands that there is the change made by Child in the bank
– LeandroLuk
@Leandroluk Exactly using the
<
, where possession comes from the parent component. But if you want to update the parent data coming from the child, the ideal is to create the bind of a method for the child to send the change to the parent rather than changing the parent model.– lenilsondc
my situation is, I have a list of users, which opens a div with a user’s Details. in my code today, when I change the Details, it is changing the list, and it should not be done because at the exact moment the bank changes, my code already updates "reactively"
– LeandroLuk
@Leandroluk Is that probably the two are the same model. Using the
<
in Binding does not prevent this?– lenilsondc
@Leandroluk I updated the answer with a working code. Also, there was a typo in the parameter
bindings
who was alonebinding
.– lenilsondc