# Lifecycle pageproperty

**URL:** <https://forum.radzen.com/t/lifecycle-pageproperty/6578>\
**Category:** Angular\
**Created:** [February 5, 2021, 2:05pm UTC](https://forum.radzen.com/t/lifecycle-pageproperty/6578 "2021-02-05T14:05:38Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![mcanavar](https://forum.radzen.com/letter_avatar_proxy/v4/letter/m/ee59a6/32.png) [@mcanavar](https://forum.radzen.com/u/mcanavar)\
**Post date:** [February 5, 2021, 2:05pm UTC](https://forum.radzen.com/t/lifecycle-pageproperty/6578/1 "2021-02-05T14:05:38Z")

</div>

Hi Radzen,

I'm using a custom method to retrieve some user info per page ( while there is no secure alternative for global variables or objects that can be accessed across pages ).

I've noticed that the object retrieved from this custom method ( similar like the UserPersonData from radzen demo / examples ). has a short lifecycle .

Explaining: Accessing the values of the object returned from the custom method can be accessed and used within the invoke if then structure and gets lost if used outside the invoke in the next statement or DataGrd filter .

does this seems familiar ? or could it be that the page has to many properties and can only hold a limited number of properties ?

So using this property object a second time gives an "can not get value from undefined" erros.

---

<div class="post-metadata">

**Author:** ![korchev](https://forum.radzen.com/user_avatar/forum.radzen.com/korchev/32/4_2.png) [@korchev](https://forum.radzen.com/u/korchev)\
**Post date:** [February 5, 2021, 2:23pm UTC](https://forum.radzen.com/t/lifecycle-pageproperty/6578/2 "2021-02-05T14:23:40Z")

</div>

There is no limitation of the number of page properties and also there is no life cycle. Once a page property is initialized (via Set property action) it will remain for as long as the page is active (e.g. the user does not navigate away).

How does your code which sets the property looks like? And how does the other action which uses it (and leads to cannot get value from undefined) look like?

---

<div class="post-metadata">

**Author:** ![mcanavar](https://forum.radzen.com/letter_avatar_proxy/v4/letter/m/ee59a6/32.png) [@mcanavar](https://forum.radzen.com/u/mcanavar)\
**Post date:** [February 5, 2021, 3:01pm UTC](https://forum.radzen.com/t/lifecycle-pageproperty/6578/3 "2021-02-05T15:01:20Z")

</div>

I'm setting the page property after invoking the custom method like:

 ![image](https://forum.radzen.com/uploads/default/original/2X/b/b122ee77afa2287d556733bc94e6152ed5e6efdb.png)

Than I'm using this "curGidId" or the "soUser property elsewhere .

I have created curGidId to look if it something was like not able to get the property"." itemvalue .

So using it in an other invoke or filter of a datagrid:

 ![image](https://forum.radzen.com/uploads/default/original/2X/b/bfa22b4f406456707cf7519e6fdc8f778cbc5b3f.png)

So :like below works:

 ![image](https://forum.radzen.com/uploads/default/original/2X/f/f3825579182141fffd52926b147ae7750f37dd1f.png)

if the 33.1.2 Invoke is outside the 33 Invoke , it does not work.

I can send you the needed files

---

<div class="post-metadata">

**Author:** ![korchev](https://forum.radzen.com/user_avatar/forum.radzen.com/korchev/32/4_2.png) [@korchev](https://forum.radzen.com/u/korchev)\
**Post date:** [February 5, 2021, 3:15pm UTC](https://forum.radzen.com/t/lifecycle-pageproperty/6578/4 "2021-02-05T15:15:20Z")

</div>

I think I know why this happens. The UserPersonalData executes asynchronously and the code after it will run before the Then event is executed. If you need to use the properties set in the Then event then the code which uses them should be in the same Then event. Alternatively set the Condition of the getFinRunDefinities to `${soUser}`. It will then execute only if soUser is set.

---

<div class="post-metadata">

**Author:** ![mcanavar](https://forum.radzen.com/letter_avatar_proxy/v4/letter/m/ee59a6/32.png) [@mcanavar](https://forum.radzen.com/u/mcanavar)\
**Post date:** [February 5, 2021, 3:22pm UTC](https://forum.radzen.com/t/lifecycle-pageproperty/6578/5 "2021-02-05T15:22:09Z")

</div>

the execution async would explain things .. but I was thinking , that a callLoadData() , would wait for the page load to finish ?

Any global variable / object availability in Angular 11 ?  
I have to include the GidId ( Global Identification ID of the user ) on each page now .. and almost all the tables have this GidId .. Just repeating the code on each page seems not that ideal.

---

<div class="post-metadata">

**Author:** ![korchev](https://forum.radzen.com/user_avatar/forum.radzen.com/korchev/32/4_2.png) [@korchev](https://forum.radzen.com/u/korchev)\
**Post date:** [February 5, 2021, 3:30pm UTC](https://forum.radzen.com/t/lifecycle-pageproperty/6578/6 "2021-02-05T15:30:37Z")

</div>

Check this thread: [Set global property](http://forum.radzen.com/t/set-global-property/1956/2)

---

<div class="post-metadata">

**Author:** ![mcanavar](https://forum.radzen.com/letter_avatar_proxy/v4/letter/m/ee59a6/32.png) [@mcanavar](https://forum.radzen.com/u/mcanavar)\
**Post date:** [February 5, 2021, 3:39pm UTC](https://forum.radzen.com/t/lifecycle-pageproperty/6578/7 "2021-02-05T15:39:09Z")

</div>

Well ...  
That is a security issue : You can easily change the local storage and it holds only string values .  
I have looked into the form about this and did not help me .  
I have to look into switching to Blazor, but the application has grown now in the two years .. if there was a easy or even an helper to convert from the angular Radzen to Blazor .. ☹

---

<div class="post-metadata">

**Author:** ![mcanavar](https://forum.radzen.com/letter_avatar_proxy/v4/letter/m/ee59a6/32.png) [@mcanavar](https://forum.radzen.com/u/mcanavar)\
**Post date:** [February 5, 2021, 4:01pm UTC](https://forum.radzen.com/t/lifecycle-pageproperty/6578/8 "2021-02-05T16:01:12Z")

</div>

Would this fit in tho Radzen ways..

> **[Angular 11/10 Global Variable for All Components Example](https://www.itsolutionstuff.com/post/angular-10-global-variable-for-all-components-exampleexample.html)**
>
> angular 10 global variable for all components, global variable in angular 10, dynamic global variable in angular 10, angular 10 access global variable, angular global constants, angular 10 set global variable

---

<div class="post-metadata">

**Author:** ![korchev](https://forum.radzen.com/user_avatar/forum.radzen.com/korchev/32/4_2.png) [@korchev](https://forum.radzen.com/u/korchev)\
**Post date:** [February 5, 2021, 4:07pm UTC](https://forum.radzen.com/t/lifecycle-pageproperty/6578/9 "2021-02-05T16:07:47Z")

</div>

It will but you will have to use the code generation ignore list to import the global constants class where you need it.

---

<div class="post-metadata">

**Author:** ![korchev](https://forum.radzen.com/user_avatar/forum.radzen.com/korchev/32/4_2.png) [@korchev](https://forum.radzen.com/u/korchev)\
**Post date:** [February 5, 2021, 4:26pm UTC](https://forum.radzen.com/t/lifecycle-pageproperty/6578/10 "2021-02-05T16:26:44Z")

</div>

Actually if you use the \*.component.ts file you don't need to use the ignore list - that file can be edited by the user freely. You will then need to cast this to `any` and assign the property with **Execute code**

```auto
(<any>this).globalConstants.myProperty = value

```

---

<div class="post-metadata">

**Author:** ![mcanavar](https://forum.radzen.com/letter_avatar_proxy/v4/letter/m/ee59a6/32.png) [@mcanavar](https://forum.radzen.com/u/mcanavar)\
**Post date:** [February 5, 2021, 8:31pm UTC](https://forum.radzen.com/t/lifecycle-pageproperty/6578/11 "2021-02-05T20:31:49Z")

</div>

Thank you , have to try this, looks interesting if it works as expected .  
But incorporating it in the standard Radzen an option ?

---

<div class="post-metadata">

**Author:** ![mcanavar](https://forum.radzen.com/letter_avatar_proxy/v4/letter/m/ee59a6/32.png) [@mcanavar](https://forum.radzen.com/u/mcanavar)\
**Post date:** [February 9, 2021, 11:50am UTC](https://forum.radzen.com/t/lifecycle-pageproperty/6578/12 "2021-02-09T11:50:24Z")

</div>

Hi @korchev ,

I'm not (yet) a complete Angular hero, could you explain.

I'm not looking into an solution where the global variables are loaded on application start ( login , user authenticated and retrieve the user / application settings from database and set the global variables once ).  
I'm not looking for a solutions where we would have to paste same code in each \*.component.ts ( or page).

Ergo: If I would have a database table where I would store the user / application settings, and invoke a database method. on each page to retrieve the desired setting voor the page / user / application.

How would a page load event look like .

Do I have to do all page load actions like setting a page property etc. after the Then of this database method invoke .. ?

To adapt this in an existing application it would take some time to change each page because there is no "re" positioning and moving parts of the code in an event in Radzen designer ( would improve productivity a lot .. ) . Sharing some thoughts .

---

<div class="post-metadata">

**Author:** ![korchev](https://forum.radzen.com/user_avatar/forum.radzen.com/korchev/32/4_2.png) [@korchev](https://forum.radzen.com/u/korchev)\
**Post date:** [February 9, 2021, 12:15pm UTC](https://forum.radzen.com/t/lifecycle-pageproperty/6578/13 "2021-02-09T12:15:42Z")

</div>

> [@mcanavar](#):
>
> Do I have to do all page load actions like setting a page property etc. after the Then of this database method invoke .. ?

Yes, this is what Radzen currently provides out of the box.
