How to make primitive type reference for binding
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
Before, I know it is kind of stupid question but i'm interested of finding answer (Don't vote down :))
I used to have this problem with angularJS and now I'm learning angular 6 and hoped there is a solution for it (which I haven't found yet)
I've created 2 custom components. The father gets an object for binding and gives its property to the son component.
For ex.
Son Component
<div> value </div>
Father Component
<div>
<son-component [value]="config.configSonValue"></son-component>
</div>
Usage of Father
<father-component [config]="myConfig"></father-component>
I'm skipping the code because it is not relevant to the question.
This is the myConfig
value
this.sonValue = 1;
const myConfig =
configSonValue: this.sonValue // This line is the problem - loosing the reference
This makes the application run and show the 1
.
But if i'm changing the value in my this.sonValue
is not affecting the UI.
It makes sense cause the moment i'm setting the value of configSonValue
the value from this.sonValue
is being copied and not referenced while its primitive type.
Today i'm asking the user to provide me the scope object and the name of the variable he wants to bind.. and in the binding i'm doing scope[name]
.
I hoped there is something like
const myConfig =
configSonValue: angular.copyRef(this.sonValue) // wishful solution
Here is an example https://stackblitz.com/edit/angular-2ta9ug
Is there ?
angular
|
show 1 more comment
Before, I know it is kind of stupid question but i'm interested of finding answer (Don't vote down :))
I used to have this problem with angularJS and now I'm learning angular 6 and hoped there is a solution for it (which I haven't found yet)
I've created 2 custom components. The father gets an object for binding and gives its property to the son component.
For ex.
Son Component
<div> value </div>
Father Component
<div>
<son-component [value]="config.configSonValue"></son-component>
</div>
Usage of Father
<father-component [config]="myConfig"></father-component>
I'm skipping the code because it is not relevant to the question.
This is the myConfig
value
this.sonValue = 1;
const myConfig =
configSonValue: this.sonValue // This line is the problem - loosing the reference
This makes the application run and show the 1
.
But if i'm changing the value in my this.sonValue
is not affecting the UI.
It makes sense cause the moment i'm setting the value of configSonValue
the value from this.sonValue
is being copied and not referenced while its primitive type.
Today i'm asking the user to provide me the scope object and the name of the variable he wants to bind.. and in the binding i'm doing scope[name]
.
I hoped there is something like
const myConfig =
configSonValue: angular.copyRef(this.sonValue) // wishful solution
Here is an example https://stackblitz.com/edit/angular-2ta9ug
Is there ?
angular
Can you post an example showing your problem? The value should update.
– ritaj
Nov 15 '18 at 9:02
If i'm changing thethis.sonValue
it is not updating the value ofmyConfig.configSonValue
.. cause they are 2 different variables now.. It is more js question then angular actually.. Do you still want me to create some demo for it ?
– Raziza O
Nov 15 '18 at 9:04
You're not binding to a primitive, you're binding to a component prop. It's bound by reference. So yeah, demo would help.
– ritaj
Nov 15 '18 at 9:08
I've added the example link to the post
– Raziza O
Nov 15 '18 at 9:23
Well, I guess I was wrong. You could wrap your primitive in object and then it will be passed by reference. I don't know about anycopyReference
or like method in Ng2
– ritaj
Nov 15 '18 at 9:52
|
show 1 more comment
Before, I know it is kind of stupid question but i'm interested of finding answer (Don't vote down :))
I used to have this problem with angularJS and now I'm learning angular 6 and hoped there is a solution for it (which I haven't found yet)
I've created 2 custom components. The father gets an object for binding and gives its property to the son component.
For ex.
Son Component
<div> value </div>
Father Component
<div>
<son-component [value]="config.configSonValue"></son-component>
</div>
Usage of Father
<father-component [config]="myConfig"></father-component>
I'm skipping the code because it is not relevant to the question.
This is the myConfig
value
this.sonValue = 1;
const myConfig =
configSonValue: this.sonValue // This line is the problem - loosing the reference
This makes the application run and show the 1
.
But if i'm changing the value in my this.sonValue
is not affecting the UI.
It makes sense cause the moment i'm setting the value of configSonValue
the value from this.sonValue
is being copied and not referenced while its primitive type.
Today i'm asking the user to provide me the scope object and the name of the variable he wants to bind.. and in the binding i'm doing scope[name]
.
I hoped there is something like
const myConfig =
configSonValue: angular.copyRef(this.sonValue) // wishful solution
Here is an example https://stackblitz.com/edit/angular-2ta9ug
Is there ?
angular
Before, I know it is kind of stupid question but i'm interested of finding answer (Don't vote down :))
I used to have this problem with angularJS and now I'm learning angular 6 and hoped there is a solution for it (which I haven't found yet)
I've created 2 custom components. The father gets an object for binding and gives its property to the son component.
For ex.
Son Component
<div> value </div>
Father Component
<div>
<son-component [value]="config.configSonValue"></son-component>
</div>
Usage of Father
<father-component [config]="myConfig"></father-component>
I'm skipping the code because it is not relevant to the question.
This is the myConfig
value
this.sonValue = 1;
const myConfig =
configSonValue: this.sonValue // This line is the problem - loosing the reference
This makes the application run and show the 1
.
But if i'm changing the value in my this.sonValue
is not affecting the UI.
It makes sense cause the moment i'm setting the value of configSonValue
the value from this.sonValue
is being copied and not referenced while its primitive type.
Today i'm asking the user to provide me the scope object and the name of the variable he wants to bind.. and in the binding i'm doing scope[name]
.
I hoped there is something like
const myConfig =
configSonValue: angular.copyRef(this.sonValue) // wishful solution
Here is an example https://stackblitz.com/edit/angular-2ta9ug
Is there ?
angular
angular
edited Nov 15 '18 at 9:23
Raziza O
asked Nov 15 '18 at 8:57
Raziza ORaziza O
770724
770724
Can you post an example showing your problem? The value should update.
– ritaj
Nov 15 '18 at 9:02
If i'm changing thethis.sonValue
it is not updating the value ofmyConfig.configSonValue
.. cause they are 2 different variables now.. It is more js question then angular actually.. Do you still want me to create some demo for it ?
– Raziza O
Nov 15 '18 at 9:04
You're not binding to a primitive, you're binding to a component prop. It's bound by reference. So yeah, demo would help.
– ritaj
Nov 15 '18 at 9:08
I've added the example link to the post
– Raziza O
Nov 15 '18 at 9:23
Well, I guess I was wrong. You could wrap your primitive in object and then it will be passed by reference. I don't know about anycopyReference
or like method in Ng2
– ritaj
Nov 15 '18 at 9:52
|
show 1 more comment
Can you post an example showing your problem? The value should update.
– ritaj
Nov 15 '18 at 9:02
If i'm changing thethis.sonValue
it is not updating the value ofmyConfig.configSonValue
.. cause they are 2 different variables now.. It is more js question then angular actually.. Do you still want me to create some demo for it ?
– Raziza O
Nov 15 '18 at 9:04
You're not binding to a primitive, you're binding to a component prop. It's bound by reference. So yeah, demo would help.
– ritaj
Nov 15 '18 at 9:08
I've added the example link to the post
– Raziza O
Nov 15 '18 at 9:23
Well, I guess I was wrong. You could wrap your primitive in object and then it will be passed by reference. I don't know about anycopyReference
or like method in Ng2
– ritaj
Nov 15 '18 at 9:52
Can you post an example showing your problem? The value should update.
– ritaj
Nov 15 '18 at 9:02
Can you post an example showing your problem? The value should update.
– ritaj
Nov 15 '18 at 9:02
If i'm changing the
this.sonValue
it is not updating the value of myConfig.configSonValue
.. cause they are 2 different variables now.. It is more js question then angular actually.. Do you still want me to create some demo for it ?– Raziza O
Nov 15 '18 at 9:04
If i'm changing the
this.sonValue
it is not updating the value of myConfig.configSonValue
.. cause they are 2 different variables now.. It is more js question then angular actually.. Do you still want me to create some demo for it ?– Raziza O
Nov 15 '18 at 9:04
You're not binding to a primitive, you're binding to a component prop. It's bound by reference. So yeah, demo would help.
– ritaj
Nov 15 '18 at 9:08
You're not binding to a primitive, you're binding to a component prop. It's bound by reference. So yeah, demo would help.
– ritaj
Nov 15 '18 at 9:08
I've added the example link to the post
– Raziza O
Nov 15 '18 at 9:23
I've added the example link to the post
– Raziza O
Nov 15 '18 at 9:23
Well, I guess I was wrong. You could wrap your primitive in object and then it will be passed by reference. I don't know about any
copyReference
or like method in Ng2– ritaj
Nov 15 '18 at 9:52
Well, I guess I was wrong. You could wrap your primitive in object and then it will be passed by reference. I don't know about any
copyReference
or like method in Ng2– ritaj
Nov 15 '18 at 9:52
|
show 1 more comment
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53315643%2fhow-to-make-primitive-type-reference-for-binding%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53315643%2fhow-to-make-primitive-type-reference-for-binding%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you post an example showing your problem? The value should update.
– ritaj
Nov 15 '18 at 9:02
If i'm changing the
this.sonValue
it is not updating the value ofmyConfig.configSonValue
.. cause they are 2 different variables now.. It is more js question then angular actually.. Do you still want me to create some demo for it ?– Raziza O
Nov 15 '18 at 9:04
You're not binding to a primitive, you're binding to a component prop. It's bound by reference. So yeah, demo would help.
– ritaj
Nov 15 '18 at 9:08
I've added the example link to the post
– Raziza O
Nov 15 '18 at 9:23
Well, I guess I was wrong. You could wrap your primitive in object and then it will be passed by reference. I don't know about any
copyReference
or like method in Ng2– ritaj
Nov 15 '18 at 9:52