New-UDDynamic -ArgmentList not working

Product: PowerShell Universal
Version: 2.6.2

Hello,

The ArgumentList parameter does not seem to work for New-UDDynamic after modifying the variable and then synchronizing New-UDDynamic.
The old value remains displayed.

See the example below:

New-UDPage -Name 'test' -Url '/test' -Content { 
    $test = 'old value' 
    New-UDDynamic -Id 'dynamic' -Content {
        New-UDTypography -Text $ArgumentList[0]
    } -ArgumentList $test

    $test = 'new value'
    Sync-UDElement -Id 'dynamic'
}

Any ideas ?

The argument list won’t be refreshed in this case. You could use a $Session variable instead.

New-UDPage -Name 'test' -Url '/test' -Content { 
    $Session:test = 'old value' 
    New-UDDynamic -Id 'dynamic' -Content {
        New-UDTypography -Text $Session:test
    } 

    $Session:test = 'new value'
    Sync-UDElement -Id 'dynamic'
}

Thank you for the answer.

If I understand correctly, if I need the $test variable not to be on the Session scope so as not to impact the same page that would be open in another tab of the browser then I could not use New-UDDynamic?

If I take a basic example (see code below) and open this page in 2 browser tabs then:

  • If I click on the button of the first tab, $test will take the value “new value”
  • If I refresh the second tab, $test will also have taken the value “new value”

=> This is exactly what I want to avoid.

New-UDPage -Name 'test' -Url '/test' -Content {  
    if (!$Session:test) {
        $Session:test = 'old value' 
    }

    New-UDDynamic -Id 'dynamic' -Content {
        New-UDTypography -Text $Session:test
    } 

    New-UDButton -Text 'Change $test' -OnClick { 
        $Session:test = 'new value'
        Sync-UDElement -Id 'dynamic'
    }
}

In this case, is my only solution to use the Set-UDElement, Add-UDElement, Clear-UDElement commands to replace the use of New-UDDynamic?

Please help me understand :slight_smile: