Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Daniel Rogers 143 posts 742 karma points
    Jan 13, 2025 @ 23:28
    Daniel Rogers
    0

    AngularJs $watch only tiggering once

    Trying to watch a value in a config section of datatype. from another value.

    The value being watched is a multivalue. refered to as docTypeAliases.

    The custom value has this code to do the watching

    $scope.$parent.$parent.$watch('preValues[0].value', function (e,  args) {
    var fString = '';
    if (e != null) {
        console.log(e)
        angular.forEach(e, function (dt) {
            fString = fString + dt.value + ","
        });
        $scope.ProfileList = undefined;
    }
    GetAvailableBlocks(fString);
        $scope.loading = false;
    });
    

    The watch is triggered initally when creatinf or loading the dataType initally. But when a new value is added to the docTypeAliases value it never triggers.

    Can any one surgest a better way.

    I would normally setup an event trigger but as using umbraco default value editor I cant do that.

    Further testing reveals that the trigger only gets triggered when I delete a value from docTypeAliases

  • Daniel Rogers 143 posts 742 karma points
    Jan 14, 2025 @ 01:29
    Daniel Rogers
    100

    figured it out.

    The watch dosent monitor the contents of the array.

    Solution was to monitor the length

    $scope.$parent.$parent.$watch('preValues[0].value.length', function (e,  args) {
    .........
    }   
    

    This now triggers everytime a value is added or deleted.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies